diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index b0f10510a..05393756c 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -131,9 +131,13 @@ jobs: matrix: sdk: [ 2.19.6, stable ] analyzer: - # We only have one version currently, but we'll leave this CI step in place - # for the next time we need to support multiple analyzer versions. - - ^5.1.0 + - ^5.13.0 # This should match the lower bound + - ^6.0.0 + exclude: + # Analyzer 6 only resolves in Dart 3 + - sdk: 2.19.6 + analyzer: ^6.0.0 + steps: - uses: actions/checkout@v4 - id: setup-dart diff --git a/lib/src/builder/codegen/typed_map_impl_generator.dart b/lib/src/builder/codegen/typed_map_impl_generator.dart index 89c796f4b..e27968925 100644 --- a/lib/src/builder/codegen/typed_map_impl_generator.dart +++ b/lib/src/builder/codegen/typed_map_impl_generator.dart @@ -556,7 +556,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator { for (var i = 0; i < mixins.length; i++) { final mixin = mixins[i]; final typeArguments = mixin.typeArguments?.toSource() ?? ''; - final names = TypedMapNames(mixin.name.name); + final names = TypedMapNames(mixin.nameWithPrefix); header.write('${names.consumerName}$typeArguments'); header.write(','); // Add a space at the beginning of the line so that dartfmt indents it diff --git a/lib/src/builder/parsing/ast_util.dart b/lib/src/builder/parsing/ast_util.dart index d34409d49..2294bb273 100644 --- a/lib/src/builder/parsing/ast_util.dart +++ b/lib/src/builder/parsing/ast_util.dart @@ -69,7 +69,17 @@ extension TypeAnnotationNameHelper on TypeAnnotation { /// field of [Identifier]s. extension TypeNameHelper on NamedType { /// The type name without any namespace prefixes. - String get nameWithoutPrefix => name.nameWithoutPrefix; + String get nameWithoutPrefix => name2.lexeme; + + /// The type name including the namespace prefix. + String get nameWithPrefix { + final prefix = importPrefix?.name.lexeme; + final name = name2.lexeme; + return [ + if (prefix != null) prefix, + name, + ].join('.'); + } } /// Utilities related to simplifying access to node identifier fields. diff --git a/lib/src/builder/parsing/declarations.dart b/lib/src/builder/parsing/declarations.dart index 1bdb384ae..a6c630a55 100644 --- a/lib/src/builder/parsing/declarations.dart +++ b/lib/src/builder/parsing/declarations.dart @@ -204,7 +204,7 @@ mixin _TypedMapMixinShorthandDeclaration { .toList(); if (badConstraints != null && badConstraints.isNotEmpty) { - final badConstraintsString = badConstraints.map((c) => c.name.name).join(', '); + final badConstraintsString = badConstraints.map((c) => c.nameWithPrefix).join(', '); final suggestedImplName = mixin.name.name.endsWith('Mixin') ? mixin.name.name.replaceFirst(RegExp(r'Mixin$'), '') @@ -229,7 +229,7 @@ extension on Union { /// This is the safest way to retrieve that information because it takes /// into account the nature of the [Union] typing of `props`. List get allPropsMixins => this.switchCase( - (a) => a.nodeHelper.mixins.map((name) => name.name.name).toList(), + (a) => a.nodeHelper.mixins.map((name) => name.nameWithPrefix).toList(), (b) => [b.name.name], ); } diff --git a/pubspec.yaml b/pubspec.yaml index 0f3e4a77d..9cc175313 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ environment: dependencies: collection: ^1.15.0 - analyzer: ^5.13.0 + analyzer: '>=5.13.0 <7.0.0' build: ^2.0.0 dart_style: ^2.0.0 js: ^0.6.1+1 diff --git a/test/vm_tests/builder/parsing/ast_util/classish_declaration_test.dart b/test/vm_tests/builder/parsing/ast_util/classish_declaration_test.dart index 5ca27c3dd..5bfe6a424 100644 --- a/test/vm_tests/builder/parsing/ast_util/classish_declaration_test.dart +++ b/test/vm_tests/builder/parsing/ast_util/classish_declaration_test.dart @@ -65,7 +65,7 @@ main() { expect(parseAndGetSingleClassish(''' abstract class Foo implements Bar, Baz {} - ''').interfaces.map((i) => i.name.name), ['Bar', 'Baz']); + ''').interfaces.map((i) => i.name2.name), ['Bar', 'Baz']); }); test('withClause', () { @@ -105,7 +105,7 @@ main() { expect(parseAndGetSingleClassish(''' class Foo extends Bar {} - ''').superclass?.name.name, 'Bar'); + ''').superclass?.name2.name, 'Bar'); }); test('mixins', () { @@ -115,13 +115,13 @@ main() { expect(parseAndGetSingleClassish(''' class Foo extends Object with Bar, Baz {} - ''').mixins.map((m) => m.name.name), ['Bar', 'Baz']); + ''').mixins.map((m) => m.name2.name), ['Bar', 'Baz']); }); test('allSuperTypes', () { expect(parseAndGetSingleClassish(''' class Foo extends Bar with Baz implements Qux {} - ''').allSuperTypes.map((m) => m.name.name), unorderedEquals(['Bar', 'Baz', 'Qux'])); + ''').allSuperTypes.map((m) => m.name2.name), unorderedEquals(['Bar', 'Baz', 'Qux'])); }); }); }); @@ -148,7 +148,7 @@ main() { expect(parseAndGetSingleClassish(''' abstract class Foo = Object with Something implements Bar, Baz; - ''').interfaces.map((i) => i.name.name), ['Bar', 'Baz']); + ''').interfaces.map((i) => i.name2.name), ['Bar', 'Baz']); }); test('withClause', () { @@ -180,19 +180,19 @@ main() { test('superclass', () { expect(parseAndGetSingleClassish(''' class Foo = Bar with Baz; - ''').superclass?.name.name, 'Bar'); + ''').superclass?.name2.name, 'Bar'); }); test('mixins', () { expect(parseAndGetSingleClassish(''' class Foo = Object with Bar, Baz; - ''').mixins.map((m) => m.name.name), ['Bar', 'Baz']); + ''').mixins.map((m) => m.name2.name), ['Bar', 'Baz']); }); test('allSuperTypes', () { expect(parseAndGetSingleClassish(''' class Foo = Bar with Baz implements Qux; - ''').allSuperTypes.map((m) => m.name.name), unorderedEquals(['Bar', 'Baz', 'Qux'])); + ''').allSuperTypes.map((m) => m.name2.name), unorderedEquals(['Bar', 'Baz', 'Qux'])); }); }); }); @@ -232,7 +232,7 @@ main() { expect(parseAndGetSingleClassish(''' mixin Foo on Bar implements Baz {} - ''').interfaces.map((i) => i.name.name), unorderedEquals(['Bar', 'Baz'])); + ''').interfaces.map((i) => i.name2.name), unorderedEquals(['Bar', 'Baz'])); }); test('withClause', () { @@ -268,7 +268,7 @@ main() { test('allSuperTypes', () { expect(parseAndGetSingleClassish(''' mixin Foo on Bar implements Baz {} - ''').allSuperTypes.map((m) => m.name.name), unorderedEquals(['Bar', 'Baz'])); + ''').allSuperTypes.map((m) => m.name2.name), unorderedEquals(['Bar', 'Baz'])); }); }); }); diff --git a/test/vm_tests/builder/parsing/ast_util_test.dart b/test/vm_tests/builder/parsing/ast_util_test.dart index c08beefcd..39020d9e2 100644 --- a/test/vm_tests/builder/parsing/ast_util_test.dart +++ b/test/vm_tests/builder/parsing/ast_util_test.dart @@ -152,17 +152,28 @@ main() { foo.SomeTypeName foo; ''')).nameWithoutPrefix, 'SomeTypeName'); }); + + test('nameWithPrefix', () { + expect(TypeNameHelper(parseAndGetSingleWithType(''' + SomeTypeName foo; + ''')).nameWithPrefix, 'SomeTypeName'); + + expect(TypeNameHelper(parseAndGetSingleWithType(''' + foo.SomeTypeName foo; + ''')).nameWithPrefix, 'foo.SomeTypeName'); + }); }); group('NameHelper', () { test('nameWithoutPrefix', () { - expect(NameHelper(parseAndGetFirstWithType(''' - SomeName foo; - ''')).nameWithoutPrefix, 'SomeName'); - - expect(NameHelper(parseAndGetFirstWithType(''' - foo.SomeName foo; - ''')).nameWithoutPrefix, 'SomeName'); + final identifier = parseAndGetSingleWithType(''' + example() => identifier; + ''').expression as Identifier; + expect(NameHelper(identifier).nameWithoutPrefix, 'identifier'); + + expect(NameHelper(parseAndGetFirstWithType(''' + example() => foo.identifier; + ''')).nameWithoutPrefix, 'identifier'); }); });