Skip to content

Commit 0d0bf4a

Browse files
authored
Correct the wildcard tests for import prefixes. (#3866)
An unrelated fix, #3865, revealed that the wildcard-variables experiment was not actually enabled in tests; the SDK constraint used in test packages needs to be '^3.6.0'. With that fix, there are some questions about how much dartdoc should be doing to keep wildcards "non-binding" and how much the analyzer should be doing. So that is raised in #3769 (comment).
1 parent 94c185a commit 0d0bf4a

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

lib/src/model/comment_referable.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ library;
77

88
import 'dart:core';
99

10+
import 'package:analyzer/dart/analysis/features.dart';
1011
import 'package:analyzer/dart/element/element.dart';
1112
import 'package:analyzer/dart/element/scope.dart';
1213
import 'package:collection/collection.dart';
1314
import 'package:dartdoc/src/model/library.dart';
1415
import 'package:dartdoc/src/model/model_element.dart';
1516
import 'package:dartdoc/src/model/nameable.dart';
17+
import 'package:dartdoc/src/model/prefix.dart';
1618
import 'package:meta/meta.dart';
1719

1820
class _ReferenceChildrenLookup {
@@ -55,6 +57,12 @@ mixin CommentReferable implements Nameable {
5557
// First attempt: Ask analyzer's `Scope.lookup` API.
5658
var result = _lookupViaScope(referenceLookup, filter: filter);
5759
if (result != null) {
60+
if (result is Prefix &&
61+
result.name == '_' &&
62+
library!.element.featureSet.isEnabled(Feature.wildcard_variables)) {
63+
// A wildcard import prefix is non-binding.
64+
continue;
65+
}
5866
return result;
5967
}
6068

lib/src/model/library.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analyzer/dart/analysis/features.dart';
56
import 'package:analyzer/dart/element/element.dart';
67
import 'package:analyzer/dart/element/scope.dart';
78
import 'package:analyzer/source/line_info.dart';
@@ -442,6 +443,11 @@ class Library extends ModelElement
442443
// ambiguous. dart-lang/dartdoc#2683.
443444
for (var MapEntry(key: prefix, value: libraries)
444445
in _prefixToLibrary.entries) {
446+
if (prefix == '_' &&
447+
element.featureSet.isEnabled(Feature.wildcard_variables)) {
448+
// A wildcard import prefix is non-binding.
449+
continue;
450+
}
445451
referenceChildrenBuilder.putIfAbsent(prefix, () => libraries.first);
446452
}
447453
return referenceChildrenBuilder;

test/dartdoc_test_base.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract class DartdocTestBase {
4141

4242
String get dartCoreUrlPrefix => 'https://api.dart.dev/stable/3.2.0/dart-core';
4343

44-
String get sdkConstraint => '>=3.3.0 <4.0.0';
44+
String get sdkConstraint => '>=3.6.0 <4.0.0';
4545

4646
List<String> get experiments => ['wildcard-variables'];
4747

test/prefixes_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ int x = 0;
3636
);
3737
}
3838

39-
@FailingTest(issue: 'https://github.com/dart-lang/dartdoc/issues/3769')
4039
void test_referenced_wildcard() async {
4140
var library = await bootPackageWithLibrary(
4241
'''

0 commit comments

Comments
 (0)