Skip to content

Commit

Permalink
Correct the wildcard tests for import prefixes. (#3866)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
srawlins committed Sep 4, 2024
1 parent 94c185a commit 0d0bf4a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/src/model/comment_referable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ library;

import 'dart:core';

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/scope.dart';
import 'package:collection/collection.dart';
import 'package:dartdoc/src/model/library.dart';
import 'package:dartdoc/src/model/model_element.dart';
import 'package:dartdoc/src/model/nameable.dart';
import 'package:dartdoc/src/model/prefix.dart';
import 'package:meta/meta.dart';

class _ReferenceChildrenLookup {
Expand Down Expand Up @@ -55,6 +57,12 @@ mixin CommentReferable implements Nameable {
// First attempt: Ask analyzer's `Scope.lookup` API.
var result = _lookupViaScope(referenceLookup, filter: filter);
if (result != null) {
if (result is Prefix &&
result.name == '_' &&
library!.element.featureSet.isEnabled(Feature.wildcard_variables)) {
// A wildcard import prefix is non-binding.
continue;
}
return result;
}

Expand Down
6 changes: 6 additions & 0 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/scope.dart';
import 'package:analyzer/source/line_info.dart';
Expand Down Expand Up @@ -442,6 +443,11 @@ class Library extends ModelElement
// ambiguous. dart-lang/dartdoc#2683.
for (var MapEntry(key: prefix, value: libraries)
in _prefixToLibrary.entries) {
if (prefix == '_' &&
element.featureSet.isEnabled(Feature.wildcard_variables)) {
// A wildcard import prefix is non-binding.
continue;
}
referenceChildrenBuilder.putIfAbsent(prefix, () => libraries.first);
}
return referenceChildrenBuilder;
Expand Down
2 changes: 1 addition & 1 deletion test/dartdoc_test_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class DartdocTestBase {

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

String get sdkConstraint => '>=3.3.0 <4.0.0';
String get sdkConstraint => '>=3.6.0 <4.0.0';

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

Expand Down
1 change: 0 additions & 1 deletion test/prefixes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ int x = 0;
);
}

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

0 comments on commit 0d0bf4a

Please sign in to comment.