From 8c6366e66e412f4a790d1241855163bba190e17b Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 26 May 2026 10:05:28 -0700 Subject: [PATCH] Augment. Deprecate ExtensionTypeDeclaration.primaryConstructor, use namePart instead. Extension type augmentations do not have representation declarations, so an `ExtensionTypeDeclaration` can no longer always expose its name through a primary constructor. Add `ExtensionTypeDeclaration.namePart` as the canonical API for the declared name and type parameters, and keep `primaryConstructor` as a deprecated compatibility API for introductory declarations. Report `extensionTypeAugmentationHasRepresentation` when an augmentation writes representation syntax. This keeps the parser recovery explicit: the augmentation still gets a plain `namePart`, while the invalid representation is diagnosed instead of being modeled as the declaration's primary constructor. Synthesize recovery representation and primary constructor fragments only for the element model when an extension type has no introductory declaration. Migrate analyzer, analysis server, analyzer plugin, and linter clients to read extension type names and type parameters from `namePart`. Change-Id: I59dd957ac38f087c861b993caf246986dcdac713 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505067 Reviewed-by: Johnni Winther Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- .../computer_document_highlights.dart | 2 +- .../lib/src/computer/computer_highlights.dart | 2 +- .../lib/src/computer/computer_hover.dart | 2 +- .../lib/src/computer/computer_outline.dart | 6 +- .../domains/analysis/occurrences_dart.dart | 5 +- .../dart/in_scope_completion_pass.dart | 10 +- .../src/services/correction/sort_members.dart | 2 +- .../refactoring/legacy/refactoring.dart | 2 +- .../refactoring/move_top_level_to_file.dart | 2 +- .../relevance_table_generator.dart | 2 +- pkg/analyzer/CHANGELOG.md | 3 +- pkg/analyzer/api.txt | 5 +- pkg/analyzer/lib/dart/element/element.dart | 23 +- .../lib/src/dart/analysis/defined_names.dart | 13 +- .../lib/src/dart/analysis/driver.dart | 2 +- .../lib/src/dart/analysis/file_state.dart | 4 +- pkg/analyzer/lib/src/dart/analysis/index.dart | 2 +- .../src/dart/analysis/referenced_names.dart | 4 +- .../lib/src/dart/analysis/results.dart | 2 +- pkg/analyzer/lib/src/dart/ast/ast.dart | 66 ++- .../lib/src/dart/ast/to_source_visitor.dart | 2 +- .../lib/src/dart/element/element.dart | 30 ++ pkg/analyzer/lib/src/dart/element/member.dart | 4 + .../lib/src/dart/resolver/scope_context.dart | 12 +- .../error/duplicate_definition_verifier.dart | 2 +- .../member_duplicate_definition_verifier.dart | 2 +- .../src/error/widget_preview_verifier.dart | 3 +- pkg/analyzer/lib/src/fasta/ast_builder.dart | 21 +- pkg/analyzer/lib/src/fine/manifest_item.dart | 10 + .../lib/src/generated/error_verifier.dart | 31 +- .../src/summary2/default_types_builder.dart | 4 +- .../lib/src/summary2/element_builder.dart | 66 ++- .../lib/src/summary2/informative_data.dart | 18 +- .../lib/src/summary2/metadata_resolver.dart | 7 +- .../lib/src/summary2/simply_bounded.dart | 2 +- .../dart/element/fragment_offset_test.dart | 2 +- .../src/dart/parser/extension_type_test.dart | 345 +++++-------- .../dart/resolution/extension_type_test.dart | 166 ++++--- ...on_of_different_declaration_kind_test.dart | 4 +- ...ugmentation_return_type_mismatch_test.dart | 8 +- ...ugmentation_type_parameter_bound_test.dart | 16 +- ...ugmentation_type_parameter_count_test.dart | 110 +---- ...augmentation_type_parameter_name_test.dart | 4 +- ...augmentation_without_declaration_test.dart | 29 +- .../duplicate_definition_test.dart | 16 +- .../diagnostics/implements_repeated_test.dart | 2 +- .../test/src/summary/element_text.dart | 2 + .../summary/elements/extension_type_test.dart | 455 ++++++++++++++++++ .../utilities/navigation/navigation_dart.dart | 2 +- pkg/linter/lib/src/ast.dart | 2 +- pkg/linter/lib/src/extensions.dart | 3 +- .../avoid_shadowing_type_parameters.dart | 2 +- .../lib/src/rules/camel_case_types.dart | 2 +- .../library_private_types_in_public_api.dart | 18 +- .../rules/non_constant_identifier_names.dart | 4 +- ...efer_constructors_over_static_methods.dart | 2 +- .../lib/src/rules/public_member_api_docs.dart | 2 +- .../rules/unnecessary_constructor_name.dart | 9 +- .../lib/src/rules/unreachable_from_main.dart | 2 +- 59 files changed, 1001 insertions(+), 579 deletions(-) diff --git a/pkg/analysis_server/lib/src/computer/computer_document_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_document_highlights.dart index 07250bcaf83..c2ab6909ce8 100644 --- a/pkg/analysis_server/lib/src/computer/computer_document_highlights.dart +++ b/pkg/analysis_server/lib/src/computer/computer_document_highlights.dart @@ -296,7 +296,7 @@ class _DartDocumentHighlightsVisitor extends GeneralizingAstVisitor { void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) { _addOccurrence( node.declaredFragment?.element, - node.primaryConstructor.typeName, + node.namePart.typeName, .Write, ); diff --git a/pkg/analysis_server/lib/src/computer/computer_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_highlights.dart index 08a0b8d390f..6bafb579421 100644 --- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart +++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart @@ -1127,7 +1127,7 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor { computer._addRegion_token(node.typeKeyword, HighlightRegionType.KEYWORD); computer._addRegion_token( - node.primaryConstructor.typeName, + node.namePart.typeName, HighlightRegionType.EXTENSION_TYPE, semanticTokenModifiers: {SemanticTokenModifiers.declaration}, ); diff --git a/pkg/analysis_server/lib/src/computer/computer_hover.dart b/pkg/analysis_server/lib/src/computer/computer_hover.dart index 033c0844c82..8040dd8e685 100644 --- a/pkg/analysis_server/lib/src/computer/computer_hover.dart +++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart @@ -237,7 +237,7 @@ class DartUnitHoverComputer { EnumDeclaration() => node.namePart.typeName, Expression() => node, ExtensionDeclaration() => node.name, - ExtensionTypeDeclaration() => node.primaryConstructor.typeName, + ExtensionTypeDeclaration() => node.namePart.typeName, FormalParameter() => node.name, FunctionDeclaration() => node.name, ImportPrefixReference() => node.name, diff --git a/pkg/analysis_server/lib/src/computer/computer_outline.dart b/pkg/analysis_server/lib/src/computer/computer_outline.dart index 8f488437993..035257e3e59 100644 --- a/pkg/analysis_server/lib/src/computer/computer_outline.dart +++ b/pkg/analysis_server/lib/src/computer/computer_outline.dart @@ -325,7 +325,7 @@ class DartUnitOutlineComputer { ExtensionTypeDeclaration node, List extensionContents, ) { - var nameToken = node.primaryConstructor.typeName; + var nameToken = node.namePart.typeName; var name = nameToken.lexeme; var element = Element( ElementKind.EXTENSION_TYPE, @@ -335,9 +335,7 @@ class DartUnitOutlineComputer { isDeprecated: _hasDeprecated(node.metadata), ), location: _getLocationToken(nameToken), - typeParameters: _getTypeParametersStr( - node.primaryConstructor.typeParameters, - ), + typeParameters: _getTypeParametersStr(node.namePart.typeParameters), ); return _nodeOutline(node, element, extensionContents); } diff --git a/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart b/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart index 9f6b6b8cce7..e57277f24a5 100644 --- a/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart +++ b/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart @@ -152,10 +152,7 @@ class DartUnitOccurrencesComputerVisitor extends GeneralizingAstVisitor { @override void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) { - _addOccurrence( - node.declaredFragment!.element, - node.primaryConstructor.typeName, - ); + _addOccurrence(node.declaredFragment!.element, node.namePart.typeName); super.visitExtensionTypeDeclaration(node); } diff --git a/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart b/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart index f5a9e16f725..15620ed5220 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart @@ -1332,12 +1332,14 @@ class InScopeCompletionPass extends SimpleAstVisitor { return; } + var namePart = node.namePart; if (offset == node.offset) { _forCompilationUnitMemberBefore(node); - } else if (offset <= node.primaryConstructor.typeName.end) { - if (offset < node.primaryConstructor.typeName.offset && + } else if (offset <= namePart.typeName.end) { + if (offset < namePart.typeName.offset && featureSet.isEnabled(Feature.primary_constructors) && - !node.primaryConstructor.hasConst) { + namePart is PrimaryConstructorDeclaration && + !namePart.hasConst) { keywordHelper.addKeyword(Keyword.CONST); } var hasSyntheticBody = @@ -1345,7 +1347,7 @@ class InScopeCompletionPass extends SimpleAstVisitor { identifierHelper( includePrivateIdentifiers: false, ).addTopLevelName(includeBody: hasSyntheticBody); - } else if (offset >= node.primaryConstructor.end && + } else if (offset >= namePart.end && (offset <= body.leftBracket.offset || body.leftBracket.isSynthetic)) { keywordHelper.addKeyword(Keyword.IMPLEMENTS); } else if (offset >= body.leftBracket.end && diff --git a/pkg/analysis_server/lib/src/services/correction/sort_members.dart b/pkg/analysis_server/lib/src/services/correction/sort_members.dart index cffb92c21b7..a8ebdfeb80a 100644 --- a/pkg/analysis_server/lib/src/services/correction/sort_members.dart +++ b/pkg/analysis_server/lib/src/services/correction/sort_members.dart @@ -188,7 +188,7 @@ class MemberSorter { name = member.namePart.typeName.lexeme; case ExtensionTypeDeclaration(): kind = _MemberKind.unitExtensionType; - name = member.primaryConstructor.typeName.lexeme; + name = member.namePart.typeName.lexeme; case ExtensionDeclaration(): kind = _MemberKind.unitExtension; name = member.name?.lexeme ?? ''; diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart index 6cc554d344b..8c491839d0f 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart @@ -622,7 +622,7 @@ abstract class RenameRefactoring implements Refactoring { } else if (node is EnumDeclaration) { nameNode = node.namePart.typeName; } else if (node is ExtensionTypeDeclaration) { - nameNode = node.primaryConstructor.typeName; + nameNode = node.namePart.typeName; } else if (node is FunctionDeclaration) { nameNode = node.name; } else if (node is MixinDeclaration) { diff --git a/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart b/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart index 5c139043bfb..aa5986f499e 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart @@ -279,7 +279,7 @@ class MoveTopLevelToFile extends ParameterizedRefactoringProducer { return null; } case ExtensionTypeDeclaration(): - nameToken = node.primaryConstructor.typeName; + nameToken = node.namePart.typeName; if (!validSelection(nameToken)) { return null; } diff --git a/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart b/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart index 54601309ab6..f2384c9da55 100644 --- a/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart +++ b/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart @@ -978,7 +978,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor { // No other completions are valid after `extension`. _unrecorded(node.typeKeyword); - _recordDeclaration(node.primaryConstructor.typeName); + _recordDeclaration(node.namePart.typeName); for (var member in node.body.members) { _recordDataForNode( diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index cbe3628702e..40ce1958233 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -3,6 +3,7 @@ * Deprecate `PackageConfigFileBuilder` in `package:analyzer/utilities/package_config_file_builder.dart`. Use `package:analyzer_testing/package_config_file_builder.dart` instead. * Deprecate `isInitializingFormal` in `FormalParameterElement`. Use type checks (`element is FieldFormalParameterElement`) instead. * Deprecate `isSuperFormal` in `FormalParameterElement`. Use type checks (`element is SuperFormalParameterElement`) instead. +* Deprecate `ExtensionTypeDeclaration.primaryConstructor`. Use `ExtensionTypeDeclaration.namePart` instead. ## 13.0.0 @@ -337,7 +338,7 @@ * Deprecate `InterfaceType.lookUpGetter3`, use `lookUpGetter` instead. * Deprecate `InterfaceType.lookUpMethod3`, use `lookUpMethod` instead. * Deprecate `InterfaceType.lookUpSetter3`, use `lookUpSetter` instead. -* Remove `PropertyAccessorFragmentImplImplicitGetter`, `PropertyAccessorFragmentImplImplicitSetter`, +* Remove `PropertyAccessorFragmentImplImplicitGetter`, `PropertyAccessorFragmentImplImplicitSetter`, and `FormalParameterFragmentImplOfImplicitSetter`, replace with `GetterFragmentImpl`, and `SetterFragmentImpl`. * Deprecate `ExtensionTypeFragment.representation2`, use `representation` instead. * Deprecate `DartType.element3`, use `element` instead. diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt index 1966cddf4e8..da76367103d 100644 --- a/pkg/analyzer/api.txt +++ b/pkg/analyzer/api.txt @@ -1133,7 +1133,8 @@ package:analyzer/dart/ast/ast.dart: declaredFragment (getter: ExtensionTypeFragment?) extensionKeyword (getter: Token) implementsClause (getter: ImplementsClause?) - primaryConstructor (getter: PrimaryConstructorDeclaration) + namePart (getter: ClassNamePart) + primaryConstructor (getter: PrimaryConstructorDeclaration, deprecated) typeKeyword (getter: Token) FieldDeclaration (class extends Object implements ClassMember, abstract, final): abstractKeyword (getter: Token?) @@ -3393,6 +3394,7 @@ package:analyzer/dart/element/element.dart: isFactory (getter: bool) isGenerative (getter: bool) isOriginDeclaration (getter: bool) + isOriginExtensionTypeRecovery (getter: bool) isOriginImplicitDefault (getter: bool) isOriginMixinApplication (getter: bool) isPrimary (getter: bool) @@ -3405,6 +3407,7 @@ package:analyzer/dart/element/element.dart: element (getter: ConstructorElement) enclosingFragment (getter: InstanceFragment?) factoryKeywordOffset (getter: int?) + isOriginExtensionTypeRecovery (getter: bool) name (getter: String) newKeywordOffset (getter: int?) nextFragment (getter: ConstructorFragment?) diff --git a/pkg/analyzer/lib/dart/element/element.dart b/pkg/analyzer/lib/dart/element/element.dart index c052cfb9e47..8e34f014967 100644 --- a/pkg/analyzer/lib/dart/element/element.dart +++ b/pkg/analyzer/lib/dart/element/element.dart @@ -241,21 +241,24 @@ abstract class ConstructorElement implements ExecutableElement { /// Whether the constructor is from an explicit [ConstructorDeclaration] /// or [PrimaryConstructorDeclaration]. /// - /// When this is `true`, [isOriginImplicitDefault] and - /// [isOriginMixinApplication] are `false`. + /// Constructor origin getters are mutually exclusive. Exactly one of the + /// following is `true`: + /// + /// * [isOriginDeclaration] + /// * [isOriginExtensionTypeRecovery] + /// * [isOriginImplicitDefault] + /// * [isOriginMixinApplication] bool get isOriginDeclaration; + /// Whether the constructor represents the recovery constructor of an extension + /// type when no introductory declaration is present in the library. + bool get isOriginExtensionTypeRecovery; + /// Whether the constructor was created because there are no explicit /// constructors. - /// - /// When this is `true`, [isOriginDeclaration] and - /// [isOriginMixinApplication] are `false`. bool get isOriginImplicitDefault; /// Whether the constructor was created for a mixin application. - /// - /// When this is `true`, [isOriginDeclaration] and - /// [isOriginImplicitDefault] are `false`. bool get isOriginMixinApplication; /// Whether this is a primary constructor. @@ -298,6 +301,10 @@ abstract class ConstructorFragment implements ExecutableFragment { /// It is `null` if the fragment is synthetic, or does not have the keyword. int? get factoryKeywordOffset; + /// Whether the constructor represents the recovery constructor of an extension + /// type when no introductory declaration is present in the library. + bool get isOriginExtensionTypeRecovery; + @override String get name; diff --git a/pkg/analyzer/lib/src/dart/analysis/defined_names.dart b/pkg/analyzer/lib/src/dart/analysis/defined_names.dart index f974b2828b6..a2b181b4506 100644 --- a/pkg/analyzer/lib/src/dart/analysis/defined_names.dart +++ b/pkg/analyzer/lib/src/dart/analysis/defined_names.dart @@ -64,11 +64,14 @@ DefinedNames computeDefinedNames(CompilationUnitImpl unit) { appendName(names.topLevelNames, member.name); member.body.members.forEach(appendClassMemberName); case ExtensionTypeDeclarationImpl(): - appendName(names.topLevelNames, member.primaryConstructor.typeName); - appendDeclaringFormalParameterNames( - member.primaryConstructor, - isExtensionType: true, - ); + appendName(names.topLevelNames, member.namePart.typeName); + if (member.namePart + case PrimaryConstructorDeclarationImpl primaryConstructor) { + appendDeclaringFormalParameterNames( + primaryConstructor, + isExtensionType: true, + ); + } member.body.members.forEach(appendClassMemberName); case FunctionDeclarationImpl(): appendName(names.topLevelNames, member.name); diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart index 258c80511f2..f13a2c81f21 100644 --- a/pkg/analyzer/lib/src/dart/analysis/driver.dart +++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart @@ -109,7 +109,7 @@ testFineAfterLibraryAnalyzerHook; // TODO(scheglov): Clean up the list of implicitly analyzed files. class AnalysisDriver { /// The version of data format, should be incremented on every format change. - static const int DATA_VERSION = 636; + static const int DATA_VERSION = 637; /// The number of exception contexts allowed to write. Once this field is /// zero, we stop writing any new exception contexts in this process. diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart index 863d17eb5e1..792146de689 100644 --- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart +++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart @@ -1030,9 +1030,7 @@ class FileState { topLevelDeclarations.add(name.lexeme); } } else if (declaration is ExtensionTypeDeclaration) { - topLevelDeclarations.add( - declaration.primaryConstructor.typeName.lexeme, - ); + topLevelDeclarations.add(declaration.namePart.typeName.lexeme); } else if (declaration is FunctionDeclaration) { topLevelDeclarations.add(declaration.name.lexeme); } else if (declaration is MixinDeclaration) { diff --git a/pkg/analyzer/lib/src/dart/analysis/index.dart b/pkg/analyzer/lib/src/dart/analysis/index.dart index d9db30e6926..5d7d300ad3b 100644 --- a/pkg/analyzer/lib/src/dart/analysis/index.dart +++ b/pkg/analyzer/lib/src/dart/analysis/index.dart @@ -915,7 +915,7 @@ class _IndexContributor extends GeneralizingAstVisitor { covariant ExtensionTypeDeclarationImpl node, ) { _addSubtype( - node.primaryConstructor.typeName.lexeme, + node.namePart.typeName.lexeme, implementsClause: node.implementsClause, memberNodes: node.body.members, ); diff --git a/pkg/analyzer/lib/src/dart/analysis/referenced_names.dart b/pkg/analyzer/lib/src/dart/analysis/referenced_names.dart index d90eb76a0e2..aaa6f4aba0b 100644 --- a/pkg/analyzer/lib/src/dart/analysis/referenced_names.dart +++ b/pkg/analyzer/lib/src/dart/analysis/referenced_names.dart @@ -109,7 +109,7 @@ class _LocalNameScope { ExtensionTypeDeclarationImpl node, ) { var scope = _LocalNameScope(enclosing); - scope.addTypeParameters(node.primaryConstructor.typeParameters); + scope.addTypeParameters(node.namePart.typeParameters); for (ClassMember member in node.body.members) { if (member is FieldDeclaration) { scope.addVariableNames(member.fields); @@ -160,7 +160,7 @@ class _LocalNameScope { case ExtensionDeclaration(): scope.add(declaration.name); case ExtensionTypeDeclaration(): - scope.add(declaration.primaryConstructor.typeName); + scope.add(declaration.namePart.typeName); case FunctionDeclaration(): scope.add(declaration.name); case MixinDeclaration(): diff --git a/pkg/analyzer/lib/src/dart/analysis/results.dart b/pkg/analyzer/lib/src/dart/analysis/results.dart index c35f72d7d4b..7cdb46e18b8 100644 --- a/pkg/analyzer/lib/src/dart/analysis/results.dart +++ b/pkg/analyzer/lib/src/dart/analysis/results.dart @@ -90,7 +90,7 @@ class DeclarationByElementLocator extends UnifyingAstVisitor { result = node; } } else if (node is ExtensionTypeDeclaration) { - if (_hasOffset(node.primaryConstructor.typeName)) { + if (_hasOffset(node.namePart.typeName)) { result = node; } } diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart index 808aedbdf8d..da115ec95dc 100644 --- a/pkg/analyzer/lib/src/dart/ast/ast.dart +++ b/pkg/analyzer/lib/src/dart/ast/ast.dart @@ -12116,7 +12116,17 @@ abstract final class ExtensionTypeDeclaration implements CompilationUnitMember { /// The `implements` clause. ImplementsClause? get implementsClause; + /// The name of the extension type. In valid code the introductory declaration + /// has [PrimaryConstructorDeclaration], and augmentations have + /// [NameWithTypeParameters]. + ClassNamePart get namePart; + /// The primary constructor of the extension type. + /// + /// Use [namePart] instead. It is a [PrimaryConstructorDeclaration] for an + /// introductory declaration with a primary constructor, and a + /// [NameWithTypeParameters] for an augmentation. + @Deprecated('Use namePart instead') PrimaryConstructorDeclaration get primaryConstructor; /// The `type` keyword. @@ -12128,7 +12138,7 @@ abstract final class ExtensionTypeDeclaration implements CompilationUnitMember { GenerateNodeProperty('augmentKeyword'), GenerateNodeProperty('extensionKeyword'), GenerateNodeProperty('typeKeyword'), - GenerateNodeProperty('primaryConstructor'), + GenerateNodeProperty('namePart'), GenerateNodeProperty('implementsClause'), GenerateNodeProperty('body'), ], @@ -12149,7 +12159,7 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl final Token typeKeyword; @generated - PrimaryConstructorDeclarationImpl _primaryConstructor; + ClassNamePartImpl _namePart; @generated ImplementsClauseImpl? _implementsClause; @@ -12169,13 +12179,13 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl required this.augmentKeyword, required this.extensionKeyword, required this.typeKeyword, - required PrimaryConstructorDeclarationImpl primaryConstructor, + required ClassNamePartImpl namePart, required ImplementsClauseImpl? implementsClause, required ClassBodyImpl body, - }) : _primaryConstructor = primaryConstructor, + }) : _namePart = namePart, _implementsClause = implementsClause, _body = body { - _becomeParentOf(primaryConstructor); + _becomeParentOf(namePart); _becomeParentOf(implementsClause); _becomeParentOf(body); } @@ -12215,17 +12225,27 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl @generated @override - PrimaryConstructorDeclarationImpl get primaryConstructor => - _primaryConstructor; + ClassNamePartImpl get namePart => _namePart; @generated - set primaryConstructor(PrimaryConstructorDeclarationImpl primaryConstructor) { - _primaryConstructor = _becomeParentOf(primaryConstructor); + set namePart(ClassNamePartImpl namePart) { + _namePart = _becomeParentOf(namePart); } + @override + @Deprecated('Use namePart instead') + PrimaryConstructorDeclarationImpl get primaryConstructor => + namePart as PrimaryConstructorDeclarationImpl; + /// Usually, the only formal parameter of the primary constructor. /// But could be `null` in invalid code. RegularFormalParameterImpl? get representationFormalParameter { + var primaryConstructor = namePart + .tryCast(); + if (primaryConstructor == null) { + return null; + } + var formalParameters = primaryConstructor.formalParameters; return formalParameters.parameters.firstOrNull.tryCast(); } @@ -12236,7 +12256,7 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl ..addToken('augmentKeyword', augmentKeyword) ..addToken('extensionKeyword', extensionKeyword) ..addToken('typeKeyword', typeKeyword) - ..addNode('primaryConstructor', primaryConstructor) + ..addNode('namePart', namePart) ..addNode('implementsClause', implementsClause) ..addNode('body', body); @@ -12255,10 +12275,8 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl @generated @override void removeChild(AstNodeImpl oldNode) { - if (identical(primaryConstructor, oldNode)) { - throw UnsupportedError( - "Cannot remove required child 'primaryConstructor'.", - ); + if (identical(namePart, oldNode)) { + throw UnsupportedError("Cannot remove required child 'namePart'."); } if (identical(implementsClause, oldNode)) { implementsClause = null; @@ -12273,8 +12291,8 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl @generated @override void replaceChild(AstNodeImpl oldNode, AstNodeImpl newNode) { - if (identical(primaryConstructor, oldNode)) { - primaryConstructor = newNode as PrimaryConstructorDeclarationImpl; + if (identical(namePart, oldNode)) { + namePart = newNode as ClassNamePartImpl; return; } if (identical(implementsClause, oldNode)) { @@ -12292,7 +12310,7 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl @override void visitChildren(AstVisitor visitor) { super.visitChildren(visitor); - primaryConstructor.accept(visitor); + namePart.accept(visitor); implementsClause?.accept(visitor); body.accept(visitor); } @@ -12305,15 +12323,15 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl @generated void visitChildrenWithHooks( AstVisitor visitor, { - void Function(PrimaryConstructorDeclarationImpl)? visitPrimaryConstructor, + void Function(ClassNamePartImpl)? visitNamePart, void Function(ImplementsClauseImpl)? visitImplementsClause, void Function(ClassBodyImpl)? visitBody, }) { super.visitChildren(visitor); - if (visitPrimaryConstructor != null) { - visitPrimaryConstructor(primaryConstructor); + if (visitNamePart != null) { + visitNamePart(namePart); } else { - primaryConstructor.accept(visitor); + namePart.accept(visitor); } if (implementsClause case var implementsClause?) { if (visitImplementsClause != null) { @@ -12335,8 +12353,8 @@ final class ExtensionTypeDeclarationImpl extends CompilationUnitMemberImpl if (super._childContainingRange(rangeOffset, rangeEnd) case var result?) { return result; } - if (primaryConstructor._containsOffset(rangeOffset, rangeEnd)) { - return primaryConstructor; + if (namePart._containsOffset(rangeOffset, rangeEnd)) { + return namePart; } if (implementsClause case var implementsClause?) { if (implementsClause._containsOffset(rangeOffset, rangeEnd)) { @@ -26808,7 +26826,7 @@ final class PrimaryConstructorBodyImpl extends ClassMemberImpl case EnumDeclarationImpl parent: return parent.namePart.tryCast(); case ExtensionTypeDeclarationImpl parent: - return parent.primaryConstructor; + return parent.namePart.tryCast(); default: return null; } diff --git a/pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart b/pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart index d54ec1ad152..7fe1c5fb465 100644 --- a/pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart +++ b/pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart @@ -523,7 +523,7 @@ class ToSourceVisitor implements AstVisitor { _visitToken(node.augmentKeyword, suffix: ' '); _visitToken(node.extensionKeyword, suffix: ' '); _visitToken(node.typeKeyword, suffix: ' '); - _visitNode(node.primaryConstructor); + _visitNode(node.namePart); _visitNode(node.implementsClause, prefix: ' '); _visitNode(node.body); } diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index 788e92aca39..b6c22f8c8fd 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -871,6 +871,7 @@ class ConstructorElementImpl extends ExecutableElementImpl 'isConst': isConst, 'isFactory': isFactory, 'isOriginDeclaration': isOriginDeclaration, + 'isOriginExtensionTypeRecovery': isOriginExtensionTypeRecovery, 'isOriginImplicitDefault': isOriginImplicitDefault, 'isOriginMixinApplication': isOriginMixinApplication, 'isPrimary': isPrimary, @@ -917,6 +918,13 @@ class ConstructorElementImpl extends ExecutableElementImpl return _firstFragment.isOriginDeclaration; } + @generated + @override + @trackedIncludedInId + bool get isOriginExtensionTypeRecovery { + return _firstFragment.isOriginExtensionTypeRecovery; + } + @generated @override @trackedIncludedInId @@ -1170,6 +1178,7 @@ class ConstructorFragmentImpl extends ExecutableFragmentImpl 'isConst': isConst, 'isFactory': isFactory, 'isOriginDeclaration': isOriginDeclaration, + 'isOriginExtensionTypeRecovery': isOriginExtensionTypeRecovery, 'isOriginImplicitDefault': isOriginImplicitDefault, 'isOriginMixinApplication': isOriginMixinApplication, 'isPrimary': isPrimary, @@ -1233,6 +1242,22 @@ class ConstructorFragmentImpl extends ExecutableFragmentImpl ); } + @generated + @override + bool get isOriginExtensionTypeRecovery { + return hasFlag( + _FragmentStorageFlag.constructorFragment_isOriginExtensionTypeRecovery, + ); + } + + @generated + set isOriginExtensionTypeRecovery(bool value) { + setFlag( + _FragmentStorageFlag.constructorFragment_isOriginExtensionTypeRecovery, + value, + ); + } + @generated bool get isOriginImplicitDefault { return hasFlag( @@ -11910,6 +11935,10 @@ enum _ConstructorElementFlags { fragment: true, element: _ElementFlagSource.firstFragment, ), + isOriginExtensionTypeRecovery( + fragment: true, + element: _ElementFlagSource.firstFragment, + ), isOriginImplicitDefault( fragment: true, element: _ElementFlagSource.firstFragment, @@ -12055,6 +12084,7 @@ enum _FragmentStorageFlag { constructorFragment_isConst, constructorFragment_isFactory, constructorFragment_isOriginDeclaration, + constructorFragment_isOriginExtensionTypeRecovery, constructorFragment_isOriginImplicitDefault, constructorFragment_isOriginMixinApplication, constructorFragment_isPrimary, diff --git a/pkg/analyzer/lib/src/dart/element/member.dart b/pkg/analyzer/lib/src/dart/element/member.dart index 7050e5b3511..f18627c3419 100644 --- a/pkg/analyzer/lib/src/dart/element/member.dart +++ b/pkg/analyzer/lib/src/dart/element/member.dart @@ -61,6 +61,10 @@ class SubstitutedConstructorElementImpl extends SubstitutedExecutableElementImpl @override bool get isOriginDeclaration => baseElement.isOriginDeclaration; + @override + bool get isOriginExtensionTypeRecovery => + baseElement.isOriginExtensionTypeRecovery; + @override bool get isOriginImplicitDefault => baseElement.isOriginImplicitDefault; diff --git a/pkg/analyzer/lib/src/dart/resolver/scope_context.dart b/pkg/analyzer/lib/src/dart/resolver/scope_context.dart index d24538e1a30..a5fcae2716e 100644 --- a/pkg/analyzer/lib/src/dart/resolver/scope_context.dart +++ b/pkg/analyzer/lib/src/dart/resolver/scope_context.dart @@ -198,18 +198,24 @@ class ScopeContext { withTypeParameterScope(element.typeParameters, () { node.nameScope = nameScope; - node.primaryConstructor.typeParameters?.accept(visitor); + node.namePart.typeParameters?.accept(visitor); node.implementsClause?.accept(visitor); if (_featureSet.isEnabled(Feature.primary_constructors)) { withInstanceScope(element, () { node.bodyScope = nameScope; node.documentationComment?.accept(visitor); - node.primaryConstructor.formalParameters.accept(visitor); + node.namePart + .tryCast() + ?.formalParameters + .accept(visitor); node.body.accept(visitor); }); } else { - node.primaryConstructor.formalParameters.accept(visitor); + node.namePart + .tryCast() + ?.formalParameters + .accept(visitor); withInstanceScope(element, () { node.bodyScope = nameScope; node.documentationComment?.accept(visitor); diff --git a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart index 1e8b170b32d..bee6e432eca 100644 --- a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart +++ b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart @@ -237,7 +237,7 @@ class DuplicateDefinitionVerifier { if (!declaredFragment.isAugmentation) { _checkDuplicateFragmentIdentifier( definedGetters, - member.primaryConstructor.typeName, + member.namePart.typeName, fragment: declaredFragment, ); } diff --git a/pkg/analyzer/lib/src/error/member_duplicate_definition_verifier.dart b/pkg/analyzer/lib/src/error/member_duplicate_definition_verifier.dart index c14b7f2db5d..be472a352eb 100644 --- a/pkg/analyzer/lib/src/error/member_duplicate_definition_verifier.dart +++ b/pkg/analyzer/lib/src/error/member_duplicate_definition_verifier.dart @@ -522,7 +522,7 @@ class MemberDuplicateDefinitionVerifier { _checkClassMembers( node.declaredFragment!, node.body.members, - primaryConstructor: node.primaryConstructor, + primaryConstructor: node.namePart.tryCast(), ); } diff --git a/pkg/analyzer/lib/src/error/widget_preview_verifier.dart b/pkg/analyzer/lib/src/error/widget_preview_verifier.dart index b6a37b6d91b..612feeb854d 100644 --- a/pkg/analyzer/lib/src/error/widget_preview_verifier.dart +++ b/pkg/analyzer/lib/src/error/widget_preview_verifier.dart @@ -104,8 +104,7 @@ class WidgetPreviewVerifier { ClassDeclaration declaration => declaration.namePart.typeName, EnumDeclaration declaration => declaration.namePart.typeName, ExtensionDeclaration declaration => declaration.name, - ExtensionTypeDeclaration declaration => - declaration.primaryConstructor.typeName, + ExtensionTypeDeclaration declaration => declaration.namePart.typeName, MixinDeclaration declaration => declaration.name, _ => null, }; diff --git a/pkg/analyzer/lib/src/fasta/ast_builder.dart b/pkg/analyzer/lib/src/fasta/ast_builder.dart index 02ba456d808..9f1f27daad8 100644 --- a/pkg/analyzer/lib/src/fasta/ast_builder.dart +++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart @@ -1587,11 +1587,13 @@ class AstBuilder extends StackListener { if (enableInlineClass) { var builder = _classLikeBuilder as _ExtensionTypeDeclarationBuilder; - primaryConstructorBuilder ??= _PrimaryConstructorBuilder( - constKeyword: null, - constructorName: null, - formalParameterList: _syntheticFormalParameterList(builder.name), - ); + if (builder.augmentKeyword == null) { + primaryConstructorBuilder ??= _PrimaryConstructorBuilder( + constKeyword: null, + constructorName: null, + formalParameterList: _syntheticFormalParameterList(builder.name), + ); + } declarations.add( builder.build( @@ -2714,6 +2716,7 @@ class AstBuilder extends StackListener { case DeclarationKind.ExtensionType: // Always valid. break; + case DeclarationKind.Class: case DeclarationKind.Enum: if (!_featureSet.isEnabled(Feature.primary_constructors)) { @@ -6621,7 +6624,7 @@ class _ExtensionTypeDeclarationBuilder extends _ClassLikeDeclarationBuilder { ExtensionTypeDeclarationImpl build({ required Token typeKeyword, required Token? constKeyword, - required _PrimaryConstructorBuilder primaryConstructorBuilder, + required _PrimaryConstructorBuilder? primaryConstructorBuilder, required ImplementsClauseImpl? implementsClause, }) { ClassBodyImpl body; @@ -6635,9 +6638,9 @@ class _ExtensionTypeDeclarationBuilder extends _ClassLikeDeclarationBuilder { ); } - var primaryConstructor = primaryConstructorBuilder.build( + var namePart = buildClassNamePart( typeName: name, - typeParameters: typeParameters, + primaryConstructorBuilder: primaryConstructorBuilder, ); return ExtensionTypeDeclarationImpl( @@ -6646,7 +6649,7 @@ class _ExtensionTypeDeclarationBuilder extends _ClassLikeDeclarationBuilder { augmentKeyword: augmentKeyword, extensionKeyword: extensionKeyword, typeKeyword: typeKeyword, - primaryConstructor: primaryConstructor, + namePart: namePart, implementsClause: implementsClause, body: body, ); diff --git a/pkg/analyzer/lib/src/fine/manifest_item.dart b/pkg/analyzer/lib/src/fine/manifest_item.dart index 393cd1544d7..19db3691e3e 100644 --- a/pkg/analyzer/lib/src/fine/manifest_item.dart +++ b/pkg/analyzer/lib/src/fine/manifest_item.dart @@ -185,6 +185,8 @@ class ConstructorItem extends ExecutableItem { flags.isConst == element.isConst && flags.isFactory == element.isFactory && flags.isOriginDeclaration == element.isOriginDeclaration && + flags.isOriginExtensionTypeRecovery == + element.isOriginExtensionTypeRecovery && flags.isOriginImplicitDefault == element.isOriginImplicitDefault && flags.isOriginMixinApplication == element.isOriginMixinApplication && flags.isPrimary == element.isPrimary && @@ -1649,6 +1651,7 @@ enum _ConstructorItemFlag { isConst, isFactory, isOriginDeclaration, + isOriginExtensionTypeRecovery, isOriginImplicitDefault, isOriginMixinApplication, isPrimary, @@ -1815,6 +1818,9 @@ extension type _ConstructorItemFlags._(int _bits) if (element.isOriginDeclaration) { bits |= _maskFor(_ConstructorItemFlag.isOriginDeclaration); } + if (element.isOriginExtensionTypeRecovery) { + bits |= _maskFor(_ConstructorItemFlag.isOriginExtensionTypeRecovery); + } if (element.isOriginImplicitDefault) { bits |= _maskFor(_ConstructorItemFlag.isOriginImplicitDefault); } @@ -1843,6 +1849,10 @@ extension type _ConstructorItemFlags._(int _bits) return _has(_ConstructorItemFlag.isOriginDeclaration); } + bool get isOriginExtensionTypeRecovery { + return _has(_ConstructorItemFlag.isOriginExtensionTypeRecovery); + } + bool get isOriginImplicitDefault { return _has(_ConstructorItemFlag.isOriginImplicitDefault); } diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 388afc20c7b..7904d0bc247 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -965,14 +965,14 @@ class ErrorVerifier extends RecursiveAstVisitor _checkForAugmentationTypeParameters( fragment: declaredFragment, firstTypeParameters: firstFragment.typeParameters, - nameOrKeywordToken: node.primaryConstructor.typeName, - typeParameterList: node.primaryConstructor.typeParameters, + nameOrKeywordToken: node.namePart.typeName, + typeParameterList: node.namePart.typeParameters, ); _enclosingClass = firstFragment.asElement2; _checkForBuiltInIdentifierAsName( - node.primaryConstructor.typeName, + node.namePart.typeName, diag.builtInIdentifierAsExtensionTypeName, ); _checkForConflictingExtensionTypeTypeVariableErrorCodes(declaredFragment); @@ -990,13 +990,13 @@ class ErrorVerifier extends RecursiveAstVisitor _checkForConflictingClassMembers(declaredFragment); _checkForConflictingGenerics( node: node, - nameToken: node.primaryConstructor.typeName, + nameToken: node.namePart.typeName, ); libraryContext.constructorFieldsVerifier.addConstructors( diagnosticReporter, declaredElement, members, - node.primaryConstructor, + node.namePart, ); _checkForNonCovariantTypeParameterPositionInRepresentationType( @@ -4291,7 +4291,7 @@ class ErrorVerifier extends RecursiveAstVisitor ) { if (fragment.element.hasImplementsSelfReference) { diagnosticReporter.report( - diag.extensionTypeImplementsItself.at(node.primaryConstructor.typeName), + diag.extensionTypeImplementsItself.at(node.namePart.typeName), ); } } @@ -4315,11 +4315,11 @@ class ErrorVerifier extends RecursiveAstVisitor diagnosticReporter.report( diag.extensionTypeInheritedMemberConflict .withArguments( - extensionTypeName: node.primaryConstructor.typeName.lexeme, + extensionTypeName: node.namePart.typeName.lexeme, memberName: memberName, ) .withContextMessages(contextMessages) - .at(node.primaryConstructor.typeName), + .at(node.namePart.typeName), ); } @@ -4346,7 +4346,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (fragment.element.hasRepresentationSelfReference) { diagnosticReporter.report( diag.extensionTypeRepresentationDependsOnItself.at( - node.primaryConstructor.typeName, + node.namePart.typeName, ), ); } @@ -4355,7 +4355,12 @@ class ErrorVerifier extends RecursiveAstVisitor void _checkForExtensionTypeRepresentationErrorCodes( ExtensionTypeDeclarationImpl node, ) { - var formalParameterList = node.primaryConstructor.formalParameters; + var primaryConstructor = node.namePart; + if (primaryConstructor is! PrimaryConstructorDeclarationImpl) { + return; + } + + var formalParameterList = primaryConstructor.formalParameters; var formalParameters = formalParameterList.parameters; if (formalParameters.isEmpty) { @@ -4397,7 +4402,7 @@ class ErrorVerifier extends RecursiveAstVisitor return; } - if (nameToken.lexeme == node.primaryConstructor.typeName.lexeme) { + if (nameToken.lexeme == primaryConstructor.typeName.lexeme) { diagnosticReporter.report(diag.memberWithClassName.at(nameToken)); } @@ -4490,7 +4495,7 @@ class ErrorVerifier extends RecursiveAstVisitor diag.extensionTypeWithAbstractMember .withArguments( methodName: member.name.lexeme, - extensionTypeName: node.primaryConstructor.typeName.lexeme, + extensionTypeName: node.namePart.typeName.lexeme, ) .at(member), ); @@ -5909,7 +5914,7 @@ class ErrorVerifier extends RecursiveAstVisitor ExtensionTypeDeclaration node, ExtensionTypeFragmentImpl fragment, ) { - var typeParameters = node.primaryConstructor.typeParameters?.typeParameters; + var typeParameters = node.namePart.typeParameters?.typeParameters; if (typeParameters == null) { return; } diff --git a/pkg/analyzer/lib/src/summary2/default_types_builder.dart b/pkg/analyzer/lib/src/summary2/default_types_builder.dart index da95f240de2..a40b54dafe3 100644 --- a/pkg/analyzer/lib/src/summary2/default_types_builder.dart +++ b/pkg/analyzer/lib/src/summary2/default_types_builder.dart @@ -55,7 +55,7 @@ class DefaultTypesBuilder { _computeBounds(element, node.typeParameters); } else if (node is ExtensionTypeDeclarationImpl) { var element = node.declaredFragment!.element; - var typeParameters = node.primaryConstructor.typeParameters; + var typeParameters = node.namePart.typeParameters; _breakSelfCycles(typeParameters); _breakRawTypeCycles(element, typeParameters); _computeBounds(element, typeParameters); @@ -101,7 +101,7 @@ class DefaultTypesBuilder { } else if (node is ExtensionDeclarationImpl) { _build(node.typeParameters); } else if (node is ExtensionTypeDeclarationImpl) { - _build(node.primaryConstructor.typeParameters); + _build(node.namePart.typeParameters); } else if (node is FunctionTypeAliasImpl) { _build(node.typeParameters); } else if (node is GenericTypeAliasImpl) { diff --git a/pkg/analyzer/lib/src/summary2/element_builder.dart b/pkg/analyzer/lib/src/summary2/element_builder.dart index f990c7465a4..66abea0d134 100644 --- a/pkg/analyzer/lib/src/summary2/element_builder.dart +++ b/pkg/analyzer/lib/src/summary2/element_builder.dart @@ -30,10 +30,52 @@ class ElementBuilder { required Map> parentChildFragments, }) { _buildTopFragments(topFragments); + _addExtensionTypeRecoveryFragments(parentChildFragments); _buildInstanceElementMembers(parentChildFragments); _buildFormalParameterElements(); } + /// Ensures that every extension type has the representation field and primary + /// constructor fragments expected by element model. + /// + /// Augmentations and invalid declarations can reach this point without those + /// fragments, so this synthesizes recovery fragments before member elements + /// are built. + void _addExtensionTypeRecoveryFragments( + Map> parentChildFragments, + ) { + for (var extensionType in libraryElement.extensionTypes) { + var firstFragment = extensionType.firstFragment; + var childFragments = parentChildFragments[firstFragment] ??= []; + + var hasPrimaryConstructor = childFragments.any( + (fragment) => fragment is ConstructorFragmentImpl && fragment.isPrimary, + ); + + if (!hasPrimaryConstructor) { + void prependChild(FragmentImpl child) { + child.enclosingFragment = firstFragment; + childFragments.insert(0, child); + } + + prependChild( + ConstructorFragmentImpl(name: 'new') + ..isPrimary = true + ..isConst = true + ..isOriginExtensionTypeRecovery = true + ..typeName = extensionType.name, + ); + + prependChild( + FieldFragmentImpl(name: null) + ..isFinal = true + ..isOriginExtensionTypeRecoveryRepresentation = true + ..hasImplicitType = true, + ); + } + } + } + /// Builds elements for formal parameter fragment chains. /// /// This runs after fragment chains are formed for constructors, methods, @@ -53,21 +95,19 @@ class ElementBuilder { void _buildInstanceElementMembers( Map> parentChildFragments, ) { - var elementChildFragments = - Map>.identity(); - - for (var entry in parentChildFragments.entries) { - var element = entry.key.element; - if (element is InstanceElementImpl) { - (elementChildFragments[element] ??= []).addAll(entry.value); + for (var instanceElement in libraryElement.children) { + if (instanceElement is! InstanceElementImpl) { + continue; } - } - for (var instanceEntry in elementChildFragments.entries) { - var instanceElement = instanceEntry.key; + var childFragments = [ + for (var instanceFragment in instanceElement.fragments) + ...?parentChildFragments[instanceFragment], + ]; + var lastInstanceFragments = {}; var lastStaticFragments = {}; - for (var fragment in instanceEntry.value) { + for (var fragment in childFragments) { var isInStaticNamespace = switch (fragment) { ConstructorFragmentImpl() => true, FieldFragmentImpl(:var isStatic) => isStatic, @@ -1595,7 +1635,7 @@ class FragmentBuilder extends ThrowingAstVisitor { void visitExtensionTypeDeclaration( covariant ExtensionTypeDeclarationImpl node, ) { - var nameToken = node.primaryConstructor.typeName; + var nameToken = node.namePart.typeName; var fragmentName = _getFragmentName(nameToken); var fragment = ExtensionTypeFragmentImpl(name: fragmentName); @@ -1609,7 +1649,7 @@ class FragmentBuilder extends ThrowingAstVisitor { var holder = _EnclosingContext(fragment: fragment); _withEnclosing(holder, () { - node.primaryConstructor.accept(this); + node.namePart.accept(this); node.body.accept(this); }); diff --git a/pkg/analyzer/lib/src/summary2/informative_data.dart b/pkg/analyzer/lib/src/summary2/informative_data.dart index e1f99b93949..f9787e5aa12 100644 --- a/pkg/analyzer/lib/src/summary2/informative_data.dart +++ b/pkg/analyzer/lib/src/summary2/informative_data.dart @@ -146,7 +146,6 @@ class InformativeDataApplier { ); } - /// This calls `withOriginDeclaration` on [fragmentList]. void _applyToAccessors( List fragmentList, List<_InfoExecutableDeclaration> infoList, @@ -244,7 +243,10 @@ class InformativeDataApplier { List fragmentList, List<_InfoConstructorDeclaration> infoList, ) { - forCorrespondingPairs(fragmentList, infoList, (fragment, info) { + forCorrespondingPairs(fragmentList.withOriginDeclaration, infoList, ( + fragment, + info, + ) { fragment.setCodeRange(info.codeOffset, info.codeLength); fragment.newKeywordOffset = info.newKeywordOffset; fragment.factoryKeywordOffset = info.factoryKeywordOffset; @@ -842,9 +844,9 @@ class _InfoBuilder { return _InfoExtensionTypeDeclaration( data: _buildInterfaceData( node, - name: node.primaryConstructor.typeName, - typeParameters: node.primaryConstructor.typeParameters, - primaryConstructor: node.primaryConstructor, + name: node.namePart.typeName, + typeParameters: node.namePart.typeParameters, + primaryConstructor: node.namePart.tryCast(), members: node.body.members, ), ); @@ -2294,6 +2296,12 @@ extension on DeferredResolutionReadingMixin { } } +extension on List { + Iterable get withOriginDeclaration { + return where((e) => e.isOriginDeclaration); + } +} + extension _ListOfPropertyAccessorFragment< T extends PropertyAccessorFragmentImpl > diff --git a/pkg/analyzer/lib/src/summary2/metadata_resolver.dart b/pkg/analyzer/lib/src/summary2/metadata_resolver.dart index b60d88e83fb..7ba735a25f2 100644 --- a/pkg/analyzer/lib/src/summary2/metadata_resolver.dart +++ b/pkg/analyzer/lib/src/summary2/metadata_resolver.dart @@ -139,11 +139,14 @@ class MetadataResolver extends ThrowingAstVisitor { covariant ExtensionTypeDeclarationImpl node, ) { node.metadata.accept(this); - node.primaryConstructor.typeParameters?.accept(this); + node.namePart.typeParameters?.accept(this); _scope = node.bodyScope!; try { - node.primaryConstructor.formalParameters.accept(this); + node.namePart + .tryCast() + ?.formalParameters + .accept(this); node.body.accept(this); } finally { _scope = _containerScope; diff --git a/pkg/analyzer/lib/src/summary2/simply_bounded.dart b/pkg/analyzer/lib/src/summary2/simply_bounded.dart index 0a84f105589..dca1aa42733 100644 --- a/pkg/analyzer/lib/src/summary2/simply_bounded.dart +++ b/pkg/analyzer/lib/src/summary2/simply_bounded.dart @@ -120,7 +120,7 @@ class SimplyBoundedDependencyWalker const [], ); } else if (node is ExtensionTypeDeclaration) { - var parameters = node.primaryConstructor.typeParameters?.typeParameters; + var parameters = node.namePart.typeParameters?.typeParameters; graphNode = SimplyBoundedNode( this, node, diff --git a/pkg/analyzer/test/dart/element/fragment_offset_test.dart b/pkg/analyzer/test/dart/element/fragment_offset_test.dart index 395d6466f4f..ee0a878a6c8 100644 --- a/pkg/analyzer/test/dart/element/fragment_offset_test.dart +++ b/pkg/analyzer/test/dart/element/fragment_offset_test.dart @@ -250,7 +250,7 @@ extension type E(int i) {} checkOffset( extensionTypeDeclaration, extensionTypeDeclaration.declaredFragment!, - extensionTypeDeclaration.primaryConstructor.typeName.offset, + extensionTypeDeclaration.namePart.typeName.offset, ); } diff --git a/pkg/analyzer/test/src/dart/parser/extension_type_test.dart b/pkg/analyzer/test/src/dart/parser/extension_type_test.dart index 4d103868867..905427fb5a9 100644 --- a/pkg/analyzer/test/src/dart/parser/extension_type_test.dart +++ b/pkg/analyzer/test/src/dart/parser/extension_type_test.dart @@ -16,7 +16,32 @@ main() { @reflectiveTest class ExtensionTypeDeclarationParserTest extends ParserDiagnosticsTest { - test_augment() { + test_augment_implementsClause() { + var parseResult = parseTestCodeWithDiagnostics(r''' +augment extension type E implements I {} +'''); + assertParsedNodeText( + parseResult.findNode.singleExtensionTypeDeclaration, + r''' +ExtensionTypeDeclaration + augmentKeyword: augment + extensionKeyword: extension + typeKeyword: type + namePart: NameWithTypeParameters + typeName: E + implementsClause: ImplementsClause + implementsKeyword: implements + interfaces + NamedType + name: I + body: BlockClassBody + leftBracket: { + rightBracket: } +''', + ); + } + + test_augment_primaryConstructor() { var parseResult = parseTestCodeWithDiagnostics(r''' augment extension type A(int it) {} // ^ @@ -29,7 +54,7 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -44,40 +69,6 @@ ExtensionTypeDeclaration '''); } - test_augment_implementsClause() { - var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) implements I {} -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. -'''); - assertParsedNodeText( - parseResult.findNode.singleExtensionTypeDeclaration, - r''' -ExtensionTypeDeclaration - augmentKeyword: augment - extensionKeyword: extension - typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration - typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) - implementsClause: ImplementsClause - implementsKeyword: implements - interfaces - NamedType - name: I - body: BlockClassBody - leftBracket: { - rightBracket: } -''', - ); - } - test_body_empty() { var parseResult = parseTestCodeWithDiagnostics(r''' extension type A(int it); @@ -88,7 +79,7 @@ extension type A(int it); ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -470,7 +461,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -516,7 +507,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -592,7 +583,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -624,9 +615,7 @@ ExtensionTypeDeclaration test_members_constructor_augment() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment E.named(); } '''); @@ -637,15 +626,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -667,9 +649,7 @@ ExtensionTypeDeclaration test_members_constructor_augment_factory_unnamed() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment factory E() => E(0); } '''); @@ -701,9 +681,7 @@ ConstructorDeclaration test_members_field_augment() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment int foo = 0; } '''); @@ -714,15 +692,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -745,9 +716,7 @@ ExtensionTypeDeclaration test_members_field_augment_static() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment static int foo = 0; } '''); @@ -758,15 +727,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -800,7 +762,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -840,7 +802,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -880,7 +842,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -908,9 +870,7 @@ ExtensionTypeDeclaration test_members_getter_augment() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment int get foo => 0; } '''); @@ -921,15 +881,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -951,9 +904,7 @@ ExtensionTypeDeclaration test_members_getter_augment_static() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment static int get foo => 0; } '''); @@ -964,15 +915,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -1005,7 +949,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1034,9 +978,7 @@ ExtensionTypeDeclaration test_members_method_augment() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment void foo() {} } '''); @@ -1047,15 +989,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -1078,9 +1013,7 @@ ExtensionTypeDeclaration test_members_method_augment_static() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment static void foo() {} } '''); @@ -1091,15 +1024,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -1123,9 +1049,7 @@ ExtensionTypeDeclaration test_members_operator_augment() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment int operator+(int other) => 0; } '''); @@ -1136,15 +1060,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -1183,7 +1100,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1215,9 +1132,7 @@ ExtensionTypeDeclaration test_members_setter_augment() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment set foo(int x) {} } '''); @@ -1228,15 +1143,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -1262,9 +1170,7 @@ ExtensionTypeDeclaration test_members_setter_augment_static() { var parseResult = parseTestCodeWithDiagnostics(r''' -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment static set foo(int x) {} } '''); @@ -1275,15 +1181,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: E - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - name: it - rightParenthesis: ) body: BlockClassBody leftBracket: { members @@ -1324,7 +1223,7 @@ ExtensionTypeDeclaration token: foo extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1349,7 +1248,7 @@ extension type const A.named(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration constKeyword: const typeName: A typeParameters: TypeParameterList @@ -1386,7 +1285,7 @@ extension type const A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration constKeyword: const typeName: A typeParameters: TypeParameterList @@ -1420,7 +1319,7 @@ extension type const A.named(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration constKeyword: const typeName: A constructorName: PrimaryConstructorName @@ -1449,7 +1348,7 @@ extension type const A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration constKeyword: const typeName: A formalParameters: FormalParameterList @@ -1477,7 +1376,7 @@ extension type const E {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: E formalParameters: FormalParameterList leftParenthesis: ( @@ -1498,7 +1397,7 @@ extension type A({int a = 0}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1529,7 +1428,7 @@ extension type A([int a = 0]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1563,7 +1462,7 @@ extension type A( ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1603,7 +1502,7 @@ extension type A({ ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1642,7 +1541,7 @@ extension type A( ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1671,7 +1570,7 @@ extension type A(this.it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1696,7 +1595,7 @@ extension type A(int it()) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1727,7 +1626,7 @@ extension type A(const int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1755,7 +1654,7 @@ extension type A(covariant int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1783,7 +1682,7 @@ extension type A(covariant final int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1813,7 +1712,7 @@ extension type A(covariant int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1839,7 +1738,7 @@ extension type A(covariant var int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1866,7 +1765,7 @@ extension type A(final int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1893,7 +1792,7 @@ extension type A(final int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1919,7 +1818,7 @@ extension type A(final it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1944,7 +1843,7 @@ extension type A(final it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1970,7 +1869,7 @@ extension type A(required int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1998,7 +1897,7 @@ extension type A(static int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2023,7 +1922,7 @@ extension type A(var it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2048,7 +1947,7 @@ extension type A(var it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2072,7 +1971,7 @@ extension type A({int it = 0}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2104,7 +2003,7 @@ extension type A({int it = 0}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2135,7 +2034,7 @@ extension type A({int? a, int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2169,7 +2068,7 @@ extension type A({int? a, int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2202,7 +2101,7 @@ extension type A({int? a, required int b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2235,7 +2134,7 @@ extension type A([int it = 0]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2267,7 +2166,7 @@ extension type A([int it = 0]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2298,7 +2197,7 @@ extension type A([int? a, int? b]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2332,7 +2231,7 @@ extension type A([int? a, int? b]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2365,7 +2264,7 @@ extension type A({required int it}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2394,7 +2293,7 @@ extension type A({required int it}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2422,7 +2321,7 @@ extension type A({required int a, int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2455,7 +2354,7 @@ extension type A({required int a, required int b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2488,7 +2387,7 @@ extension type A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2514,7 +2413,7 @@ extension type A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2539,7 +2438,7 @@ extension type A(int a, {int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2572,7 +2471,7 @@ extension type A(int a, {int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2604,7 +2503,7 @@ extension type A(int a, [int? b]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2637,7 +2536,7 @@ extension type A(int a, [int? b]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2669,7 +2568,7 @@ extension type A(int a, int b) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2699,7 +2598,7 @@ extension type A(int a, int b) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2728,7 +2627,7 @@ extension type A(int A) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2753,7 +2652,7 @@ extension type A(@foo int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2783,7 +2682,7 @@ extension type A() {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2805,7 +2704,7 @@ extension type A() {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2826,7 +2725,7 @@ extension type A(it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2850,7 +2749,7 @@ extension type A(it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2873,7 +2772,7 @@ extension type A(@foo it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2901,7 +2800,7 @@ extension type A(super.it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2926,7 +2825,7 @@ extension type A(int it,) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2952,7 +2851,7 @@ extension type A(int it,) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2979,7 +2878,7 @@ extension type E {} ExtensionTypeDeclaration extensionKeyword: extension @0 typeKeyword: type @10 - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: E @15 formalParameters: FormalParameterList leftParenthesis: ( @17 @@ -3000,7 +2899,7 @@ extension type A.named(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A typeParameters: TypeParameterList leftBracket: < @@ -3036,7 +2935,7 @@ extension type A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A typeParameters: TypeParameterList leftBracket: < @@ -3069,7 +2968,7 @@ extension type A.named(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A constructorName: PrimaryConstructorName period: . @@ -3097,7 +2996,7 @@ extension type A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -3124,7 +3023,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -3154,7 +3053,7 @@ extension type A(int it) implements B, C {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -3186,7 +3085,7 @@ extension type A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A typeParameters: TypeParameterList leftBracket: < diff --git a/pkg/analyzer/test/src/dart/resolution/extension_type_test.dart b/pkg/analyzer/test/src/dart/resolution/extension_type_test.dart index 680030efc7d..520ae739deb 100644 --- a/pkg/analyzer/test/src/dart/resolution/extension_type_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/extension_type_test.dart @@ -16,6 +16,46 @@ main() { @reflectiveTest class ExtensionTypeResolutionTest extends PubPackageResolutionTest { + test_augment_primaryConstructor() async { + var result = await resolveTestCodeWithDiagnostics(r''' +extension type A(int it) {} + +augment extension type A(int it) {} +// ^ +// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +'''); + + var node = result.findNode.extensionTypeDeclaration('augment'); + assertResolvedNodeText(node, r''' +ExtensionTypeDeclaration + augmentKeyword: augment + extensionKeyword: extension + typeKeyword: type + namePart: PrimaryConstructorDeclaration + typeName: A + formalParameters: FormalParameterList + leftParenthesis: ( + parameter: RegularFormalParameter + type: NamedType + name: int + element: dart:core::@class::int + type: int + name: it + declaredFragment: it@58 + element: isFinal isPublic + type: int + field: ::@extensionType::A::@field::it + rightParenthesis: ) + declaredFragment: new@null + element: ::@extensionType::A::@constructor::new + type: A Function(int) + body: BlockClassBody + leftBracket: { + rightBracket: } + declaredFragment: A@52 +'''); + } + test_constructor_factoryHead_named() async { var result = await resolveTestCodeWithDiagnostics(r''' extension type A(int it) { @@ -516,7 +556,7 @@ extension type A(String it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -588,7 +628,7 @@ extension type A(int it) implements num {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -704,7 +744,7 @@ extension type A({int a = 0}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -746,7 +786,7 @@ extension type A([int a = 0]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -790,7 +830,7 @@ extension type A(this.it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -826,7 +866,7 @@ extension type A(this.it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -859,7 +899,7 @@ extension type A(int it()) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -901,7 +941,7 @@ extension type A(int it()) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -942,7 +982,7 @@ extension type A(const int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -981,7 +1021,7 @@ extension type A(const int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1019,7 +1059,7 @@ extension type A(covariant int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1058,7 +1098,7 @@ extension type A(covariant int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1094,7 +1134,7 @@ extension type A(final int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1133,7 +1173,7 @@ extension type A(final int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1169,7 +1209,7 @@ extension type A(final it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1206,7 +1246,7 @@ extension type A(final it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1240,7 +1280,7 @@ extension type A(required int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1278,7 +1318,7 @@ extension type A(static int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1315,7 +1355,7 @@ extension type A(var it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1352,7 +1392,7 @@ extension type A(var it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1384,7 +1424,7 @@ extension type A({int? it}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1425,7 +1465,7 @@ extension type A({int? it}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1465,7 +1505,7 @@ extension type A({int? a, int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1516,7 +1556,7 @@ extension type A({int? a, int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1566,7 +1606,7 @@ extension type A({int? a, required int b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1614,7 +1654,7 @@ extension type A([int? it]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1655,7 +1695,7 @@ extension type A([int? it]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1695,7 +1735,7 @@ extension type A([int? a, int? b]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1746,7 +1786,7 @@ extension type A([int? a, int? b]) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1794,7 +1834,7 @@ extension type A({required int it}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1835,7 +1875,7 @@ extension type A({required int it}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1875,7 +1915,7 @@ extension type A({required int a, int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1925,7 +1965,7 @@ extension type A({required int a, required int b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -1973,7 +2013,7 @@ extension type A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2009,7 +2049,7 @@ extension type A(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2046,7 +2086,7 @@ extension type A(int a, {int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2096,7 +2136,7 @@ extension type A(int a, {int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2145,7 +2185,7 @@ extension type A(int a, {int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2195,7 +2235,7 @@ extension type A(int a, {int? b}) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2244,7 +2284,7 @@ extension type A(int a, int b) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2291,7 +2331,7 @@ extension type A(int a, int b) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2337,7 +2377,7 @@ extension type A(int A) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2375,7 +2415,7 @@ extension type A(int A) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2410,7 +2450,7 @@ extension type A(@deprecated int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2455,7 +2495,7 @@ extension type A() {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2483,7 +2523,7 @@ extension type A() {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2508,7 +2548,7 @@ extension type A(it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2542,7 +2582,7 @@ extension type A(it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2573,7 +2613,7 @@ extension type A(@deprecated it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2615,7 +2655,7 @@ extension type A(@deprecated it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2658,7 +2698,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2714,7 +2754,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2769,7 +2809,7 @@ extension type A(super.it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2804,7 +2844,7 @@ extension type A(super.it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2836,7 +2876,7 @@ extension type A(int it,) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2874,7 +2914,7 @@ extension type A(int it,) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -2913,7 +2953,7 @@ extension type E {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: E formalParameters: FormalParameterList leftParenthesis: ( @@ -2938,7 +2978,7 @@ extension type A.named(int it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A constructorName: PrimaryConstructorName period: . @@ -3098,7 +3138,7 @@ extension type A({bool it = false}) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -3305,7 +3345,7 @@ extension type A(int it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -3366,7 +3406,7 @@ extension type A(num it) { ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A formalParameters: FormalParameterList leftParenthesis: ( @@ -3455,7 +3495,7 @@ extension type A(Map it) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: A typeParameters: TypeParameterList leftBracket: < @@ -3514,7 +3554,7 @@ extension type ET<_, _, _ extends num>(int _) {} ExtensionTypeDeclaration extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: PrimaryConstructorDeclaration typeName: ET typeParameters: TypeParameterList leftBracket: < diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_test.dart index 94e582fa6c1..b719d6911c4 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_of_different_declaration_kind_test.dart @@ -489,10 +489,8 @@ augment extension A {} class A {} // ^ // [context 1] The declaration being augmented. -augment extension type A(int it) {} +augment extension type A {} // [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a extension type. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_return_type_mismatch_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_return_type_mismatch_test.dart index 692fb5671b6..0ee3f508d14 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_return_type_mismatch_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_return_type_mismatch_test.dart @@ -171,9 +171,7 @@ extension type A(int it) { int get foo => 0; } -augment extension type A(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A { augment String get foo; // ^^^^^^ // [diag.augmentationReturnTypeMismatch] The augmentation's return type 'String' must be the same as the introductory declaration's return type 'int'. @@ -187,9 +185,7 @@ extension type A(int it) { void foo() {} } -augment extension type A(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A { augment int foo(); // ^^^ // [diag.augmentationReturnTypeMismatch] The augmentation's return type 'int' must be the same as the introductory declaration's return type 'void'. diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart index 00c1ce0400a..12bab1e5918 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_bound_test.dart @@ -174,40 +174,32 @@ augment extension A {} test_extensionType_nothing_num() async { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} +augment extension type A {} // ^^^ // [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); } test_extensionType_num_int() async { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} +augment extension type A {} // ^^^ // [diag.augmentationTypeParameterBound] The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); } test_extensionType_num_nothing() async { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A {} '''); } test_extensionType_num_num() async { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A {} '''); } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart index 1545ea8d0ac..a7fd24185c9 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_count_test.dart @@ -587,11 +587,9 @@ ExtensionDeclaration test_extensionType_0_1() async { var result = await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} +augment extension type A {} // ^ // [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); var node = result.findNode.extensionTypeDeclaration( 'augment extension type A', @@ -601,7 +599,7 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: A typeParameters: TypeParameterList leftBracket: < @@ -611,22 +609,6 @@ ExtensionTypeDeclaration declaredFragment: T@53 defaultType: dynamic rightBracket: > - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - element: dart:core::@class::int - type: int - name: it - declaredFragment: it@60 - element: isFinal isPublic - type: int - field: ::@extensionType::A::@field::it - rightParenthesis: ) - declaredFragment: new@null - element: ::@extensionType::A::@constructor::new - type: A Function(int) body: BlockClassBody leftBracket: { rightBracket: } @@ -637,11 +619,9 @@ ExtensionTypeDeclaration test_extensionType_1_0() async { var result = await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} +augment extension type A {} // ^ // [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); var node = result.findNode.extensionTypeDeclaration( 'augment extension type A', @@ -651,24 +631,8 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: A - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - element: dart:core::@class::int - type: int - name: it - declaredFragment: it@60 - element: isFinal isPublic - type: int - field: ::@extensionType::A::@field::it - rightParenthesis: ) - declaredFragment: new@null - element: ::@extensionType::A::@constructor::new - type: A Function(int) body: BlockClassBody leftBracket: { rightBracket: } @@ -679,9 +643,7 @@ ExtensionTypeDeclaration test_extensionType_1_1() async { var result = await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A {} '''); var node = result.findNode.extensionTypeDeclaration( 'augment extension type A', @@ -691,7 +653,7 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: A typeParameters: TypeParameterList leftBracket: < @@ -701,22 +663,6 @@ ExtensionTypeDeclaration declaredFragment: T@56 defaultType: dynamic rightBracket: > - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - element: dart:core::@class::int - type: int - name: it - declaredFragment: it@63 - element: isFinal isPublic - type: int - field: ::@extensionType::A::@field::it - rightParenthesis: ) - declaredFragment: new@null - element: ::@extensionType::A::@constructor::new - type: A Function(int) body: BlockClassBody leftBracket: { rightBracket: } @@ -727,11 +673,9 @@ ExtensionTypeDeclaration test_extensionType_1_2() async { var result = await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} +augment extension type A {} // ^ // [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); var node = result.findNode.extensionTypeDeclaration( 'augment extension type A', @@ -741,7 +685,7 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: A typeParameters: TypeParameterList leftBracket: < @@ -755,22 +699,6 @@ ExtensionTypeDeclaration declaredFragment: U@59 defaultType: dynamic rightBracket: > - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - element: dart:core::@class::int - type: int - name: it - declaredFragment: it@66 - element: isFinal isPublic - type: int - field: ::@extensionType::A::@field::it - rightParenthesis: ) - declaredFragment: new@null - element: ::@extensionType::A::@constructor::new - type: A Function(int) body: BlockClassBody leftBracket: { rightBracket: } @@ -781,11 +709,9 @@ ExtensionTypeDeclaration test_extensionType_2_1() async { var result = await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} +augment extension type A {} // ^ // [diag.augmentationTypeParameterCount] The augmentation must have the same number of type parameters as the declaration. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); var node = result.findNode.extensionTypeDeclaration( 'augment extension type A', @@ -795,7 +721,7 @@ ExtensionTypeDeclaration augmentKeyword: augment extensionKeyword: extension typeKeyword: type - primaryConstructor: PrimaryConstructorDeclaration + namePart: NameWithTypeParameters typeName: A typeParameters: TypeParameterList leftBracket: < @@ -805,22 +731,6 @@ ExtensionTypeDeclaration declaredFragment: T@59 defaultType: dynamic rightBracket: > - formalParameters: FormalParameterList - leftParenthesis: ( - parameter: RegularFormalParameter - type: NamedType - name: int - element: dart:core::@class::int - type: int - name: it - declaredFragment: it@66 - element: isFinal isPublic - type: int - field: ::@extensionType::A::@field::it - rightParenthesis: ) - declaredFragment: new@null - element: ::@extensionType::A::@constructor::new - type: A Function(int) body: BlockClassBody leftBracket: { rightBracket: } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart index 161d328442f..be41df880d2 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_type_parameter_name_test.dart @@ -68,11 +68,9 @@ augment extension A {} test_extensionType_T_U() async { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) {} +augment extension type A {} // ^ // [diag.augmentationTypeParameterName] The augmentation type parameter must have the same name as the corresponding type parameter of the declaration. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); } diff --git a/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart index 0370a9bfad7..35310474dfe 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart @@ -1008,10 +1008,8 @@ augment extension A { test_extensionType() async { await resolveTestCodeWithDiagnostics(r''' -augment extension type A(int it) {} +augment extension type A {} // [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. '''); } @@ -1019,9 +1017,7 @@ augment extension type A(int it) {} await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A { augment A.named() : this(0); //^^^^^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. @@ -1029,13 +1025,20 @@ augment extension type A(int it) { '''); } + test_extensionType_hasPrimaryConstructor() async { + await resolveTestCodeWithDiagnostics(r''' +augment extension type A(int it) {} +// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +// ^ +// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +'''); + } + test_extensionType_instanceGetter() async { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A { augment int get foo => 0; //^^^^^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. @@ -1047,9 +1050,7 @@ augment extension type A(int it) { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A { augment void foo() {} //^^^^^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. @@ -1061,9 +1062,7 @@ augment extension type A(int it) { await resolveTestCodeWithDiagnostics(r''' extension type A(int it) {} -augment extension type A(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type A { augment set foo(int _) {} //^^^^^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. diff --git a/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart b/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart index 38696a9585e..de5b4ece640 100644 --- a/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart +++ b/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart @@ -2253,9 +2253,7 @@ extension type E(int it) { // [context 1] The corresponding getter is declared here. } -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment int foo = 0; // ^^^ // [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. @@ -2378,9 +2376,7 @@ extension type E(int it) { // [context 1] The corresponding setter is declared here. } -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment int foo = 0; // ^^^ // [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. @@ -2493,9 +2489,7 @@ extension type E(int it) { // [context 1] The corresponding getter is declared here. } -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment static int foo = 0; // ^^^ // [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. @@ -2585,9 +2579,7 @@ extension type E(int it) { // [context 1] The corresponding setter is declared here. } -augment extension type E(int it) { -// ^ -// [diag.extensionTypeAugmentationSpecifiesRepresentationField] An extension type augmentation can't specify a representation field. +augment extension type E { augment static int foo = 0; // ^^^ // [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. diff --git a/pkg/analyzer/test/src/diagnostics/implements_repeated_test.dart b/pkg/analyzer/test/src/diagnostics/implements_repeated_test.dart index 742e93d992b..d56b6e64d89 100644 --- a/pkg/analyzer/test/src/diagnostics/implements_repeated_test.dart +++ b/pkg/analyzer/test/src/diagnostics/implements_repeated_test.dart @@ -221,7 +221,7 @@ extension type A(int it) implements int {} var b = newFile('$testPackageLibPath/b.dart', r''' part of 'a.dart'; -augment extension type A(int it) implements int {} +augment extension type A implements int {} '''); await assertErrorsInFile2(a, []); diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart index 46658027899..27687332d3c 100644 --- a/pkg/analyzer/test/src/summary/element_text.dart +++ b/pkg/analyzer/test/src/summary/element_text.dart @@ -352,6 +352,7 @@ class _Element2Writer extends _AbstractElementWriter { _sink.writeHeaderFlags(e.flagsForTesting); _assertHasExactlyOneTrue([ e.isOriginDeclaration, + e.isOriginExtensionTypeRecovery, e.isOriginImplicitDefault, e.isOriginMixinApplication, ]); @@ -413,6 +414,7 @@ class _Element2Writer extends _AbstractElementWriter { _sink.writeHeaderFlags(f.flagsForTesting); _assertHasExactlyOneTrue([ f.isOriginDeclaration, + f.isOriginExtensionTypeRecovery, f.isOriginImplicitDefault, f.isOriginMixinApplication, ]); diff --git a/pkg/analyzer/test/src/summary/elements/extension_type_test.dart b/pkg/analyzer/test/src/summary/elements/extension_type_test.dart index 95cf7d9233c..dc6cad518bc 100644 --- a/pkg/analyzer/test/src/summary/elements/extension_type_test.dart +++ b/pkg/analyzer/test/src/summary/elements/extension_type_test.dart @@ -6692,6 +6692,249 @@ library test_extensionType_augmentation_chain_noIntroductoryDeclaration() async { var library = await buildLibrary(r''' +augment extension type A { + void foo1() {} +} + +augment extension type A { + void foo2() {} +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + extensionTypes + #F1 isAugmentation extension type A (nameOffset:23) (firstTokenOffset:0) (offset:23) + element: ::@extensionType::A + nextFragment: #F2 + fields + #F3 hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@field::#0 + inducedGetter: #F4 + constructors + #F5 isConst isOriginExtensionTypeRecovery isPrimary new (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@constructor::new + typeName: A + getters + #F4 isCompleteDeclaration isOriginVariable (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@getter::#1 + inducingVariable: #F3 + methods + #F6 isCompleteDeclaration isOriginDeclaration foo1 (nameOffset:34) (firstTokenOffset:29) (offset:34) + element: ::@extensionType::A::@method::foo1 + #F2 isAugmentation extension type A (nameOffset:70) (firstTokenOffset:47) (offset:70) + element: ::@extensionType::A + previousFragment: #F1 + methods + #F7 isCompleteDeclaration isOriginDeclaration foo2 (nameOffset:81) (firstTokenOffset:76) (offset:81) + element: ::@extensionType::A::@method::foo2 + extensionTypes + isSimplyBounded extension type A + reference: ::@extensionType::A + firstFragment: #F1 + representation: ::@extensionType::A::@field::#0 + primaryConstructor: ::@extensionType::A::@constructor::new + typeErasure: dynamic + fields + hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation + reference: ::@extensionType::A::@field::#0 + firstFragment: #F3 + type: dynamic + getter: ::@extensionType::A::@getter::#1 + constructors + isConst isExtensionTypeMember isOriginExtensionTypeRecovery isPrimary new + reference: ::@extensionType::A::@constructor::new + firstFragment: #F5 + getters + isExtensionTypeMember isOriginVariable + reference: ::@extensionType::A::@getter::#1 + firstFragment: #F4 + returnType: dynamic + variable: ::@extensionType::A::@field::#0 + methods + isExtensionTypeMember isOriginDeclaration foo1 + reference: ::@extensionType::A::@method::foo1 + firstFragment: #F6 + returnType: void + isExtensionTypeMember isOriginDeclaration foo2 + reference: ::@extensionType::A::@method::foo2 + firstFragment: #F7 + returnType: void +'''); + } + + test_extensionType_augmentation_chain_noIntroductoryDeclaration_emptyThenSecondaryConstructor() async { + var library = await buildLibrary(r''' +augment extension type A {} + +augment extension type A { + A.named(); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + extensionTypes + #F1 isAugmentation extension type A (nameOffset:23) (firstTokenOffset:0) (offset:23) + element: ::@extensionType::A + nextFragment: #F2 + fields + #F3 hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@field::#0 + inducedGetter: #F4 + constructors + #F5 isConst isOriginExtensionTypeRecovery isPrimary new (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@constructor::new + typeName: A + getters + #F4 isCompleteDeclaration isOriginVariable (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@getter::#1 + inducingVariable: #F3 + #F2 isAugmentation extension type A (nameOffset:52) (firstTokenOffset:29) (offset:52) + element: ::@extensionType::A + previousFragment: #F1 + constructors + #F6 isOriginDeclaration named (nameOffset:60) (firstTokenOffset:58) (offset:60) + element: ::@extensionType::A::@constructor::named + typeName: A + typeNameOffset: 58 + periodOffset: 59 + extensionTypes + isSimplyBounded extension type A + reference: ::@extensionType::A + firstFragment: #F1 + representation: ::@extensionType::A::@field::#0 + primaryConstructor: ::@extensionType::A::@constructor::new + typeErasure: dynamic + fields + hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation + reference: ::@extensionType::A::@field::#0 + firstFragment: #F3 + type: dynamic + getter: ::@extensionType::A::@getter::#1 + constructors + isConst isExtensionTypeMember isOriginExtensionTypeRecovery isPrimary new + reference: ::@extensionType::A::@constructor::new + firstFragment: #F5 + isExtensionTypeMember isOriginDeclaration named + reference: ::@extensionType::A::@constructor::named + firstFragment: #F6 + getters + isExtensionTypeMember isOriginVariable + reference: ::@extensionType::A::@getter::#1 + firstFragment: #F4 + returnType: dynamic + variable: ::@extensionType::A::@field::#0 +'''); + } + + test_extensionType_augmentation_chain_noIntroductoryDeclaration_emptyThenStaticField() async { + var library = await buildLibrary(r''' +augment extension type A {} + +augment extension type A { + static int foo = 0; +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + extensionTypes + #F1 isAugmentation extension type A (nameOffset:23) (firstTokenOffset:0) (offset:23) + element: ::@extensionType::A + nextFragment: #F2 + fields + #F3 hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@field::#0 + inducedGetter: #F4 + constructors + #F5 isConst isOriginExtensionTypeRecovery isPrimary new (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@constructor::new + typeName: A + getters + #F4 isCompleteDeclaration isOriginVariable (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@getter::#1 + inducingVariable: #F3 + #F2 isAugmentation extension type A (nameOffset:52) (firstTokenOffset:29) (offset:52) + element: ::@extensionType::A + previousFragment: #F1 + fields + #F6 hasInitializer isOriginDeclaration isStatic foo (nameOffset:69) (firstTokenOffset:69) (offset:69) + element: ::@extensionType::A::@field::foo + inducedGetter: #F7 + inducedSetter: #F8 + getters + #F7 isCompleteDeclaration isOriginVariable isStatic foo (nameOffset:) (firstTokenOffset:) (offset:69) + element: ::@extensionType::A::@getter::foo + inducingVariable: #F6 + setters + #F8 isCompleteDeclaration isOriginVariable isStatic foo (nameOffset:) (firstTokenOffset:) (offset:69) + element: ::@extensionType::A::@setter::foo + inducingVariable: #F6 + formalParameters + #F9 requiredPositional value (nameOffset:) (firstTokenOffset:) (offset:69) + element: ::@extensionType::A::@setter::foo::@formalParameter::value + extensionTypes + isSimplyBounded extension type A + reference: ::@extensionType::A + firstFragment: #F1 + representation: ::@extensionType::A::@field::#0 + primaryConstructor: ::@extensionType::A::@constructor::new + typeErasure: dynamic + fields + hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation + reference: ::@extensionType::A::@field::#0 + firstFragment: #F3 + type: dynamic + getter: ::@extensionType::A::@getter::#1 + hasInitializer isOriginDeclaration isStatic foo + reference: ::@extensionType::A::@field::foo + firstFragment: #F6 + type: int + getter: ::@extensionType::A::@getter::foo + setter: ::@extensionType::A::@setter::foo + constructors + isConst isExtensionTypeMember isOriginExtensionTypeRecovery isPrimary new + reference: ::@extensionType::A::@constructor::new + firstFragment: #F5 + getters + isExtensionTypeMember isOriginVariable + reference: ::@extensionType::A::@getter::#1 + firstFragment: #F4 + returnType: dynamic + variable: ::@extensionType::A::@field::#0 + isExtensionTypeMember isOriginVariable isStatic foo + reference: ::@extensionType::A::@getter::foo + firstFragment: #F7 + returnType: int + variable: ::@extensionType::A::@field::foo + setters + isExtensionTypeMember isOriginVariable isStatic foo + reference: ::@extensionType::A::@setter::foo + firstFragment: #F8 + formalParameters + #E0 requiredPositional value + firstFragment: #F9 + type: int + returnType: void + variable: ::@extensionType::A::@field::foo +'''); + } + + test_extensionType_augmentation_chain_noIntroductoryDeclaration_primaryConstructor() async { + var library = await buildLibrary(r''' augment extension type A(int it) { void foo1() {} } @@ -6801,6 +7044,218 @@ library '''); } + test_extensionType_augmentation_chain_noIntroductoryDeclaration_secondaryConstructor() async { + var library = await buildLibrary(r''' +augment extension type A { + A.named(); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + extensionTypes + #F1 isAugmentation extension type A (nameOffset:23) (firstTokenOffset:0) (offset:23) + element: ::@extensionType::A + fields + #F2 hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@field::#0 + inducedGetter: #F3 + constructors + #F4 isConst isOriginExtensionTypeRecovery isPrimary new (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@constructor::new + typeName: A + #F5 isOriginDeclaration named (nameOffset:31) (firstTokenOffset:29) (offset:31) + element: ::@extensionType::A::@constructor::named + typeName: A + typeNameOffset: 29 + periodOffset: 30 + getters + #F3 isCompleteDeclaration isOriginVariable (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@getter::#1 + inducingVariable: #F2 + extensionTypes + isSimplyBounded extension type A + reference: ::@extensionType::A + firstFragment: #F1 + representation: ::@extensionType::A::@field::#0 + primaryConstructor: ::@extensionType::A::@constructor::new + typeErasure: dynamic + fields + hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation + reference: ::@extensionType::A::@field::#0 + firstFragment: #F2 + type: dynamic + getter: ::@extensionType::A::@getter::#1 + constructors + isConst isExtensionTypeMember isOriginExtensionTypeRecovery isPrimary new + reference: ::@extensionType::A::@constructor::new + firstFragment: #F4 + isExtensionTypeMember isOriginDeclaration named + reference: ::@extensionType::A::@constructor::named + firstFragment: #F5 + getters + isExtensionTypeMember isOriginVariable + reference: ::@extensionType::A::@getter::#1 + firstFragment: #F3 + returnType: dynamic + variable: ::@extensionType::A::@field::#0 +'''); + } + + test_extensionType_augmentation_chain_noIntroductoryDeclaration_secondaryConstructor_unnamed() async { + var library = await buildLibrary(r''' +augment extension type A { + A(); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + extensionTypes + #F1 isAugmentation extension type A (nameOffset:23) (firstTokenOffset:0) (offset:23) + element: ::@extensionType::A + fields + #F2 hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@field::#0 + inducedGetter: #F3 + constructors + #F4 isConst isOriginExtensionTypeRecovery isPrimary new (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@constructor::new + typeName: A + #F5 isOriginDeclaration new (nameOffset:) (firstTokenOffset:29) (offset:29) + element: ::@extensionType::A::@constructor::new#1 + typeName: A + typeNameOffset: 29 + getters + #F3 isCompleteDeclaration isOriginVariable (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@getter::#1 + inducingVariable: #F2 + extensionTypes + isSimplyBounded extension type A + reference: ::@extensionType::A + firstFragment: #F1 + representation: ::@extensionType::A::@field::#0 + primaryConstructor: ::@extensionType::A::@constructor::new + typeErasure: dynamic + fields + hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation + reference: ::@extensionType::A::@field::#0 + firstFragment: #F2 + type: dynamic + getter: ::@extensionType::A::@getter::#1 + constructors + isConst isExtensionTypeMember isOriginExtensionTypeRecovery isPrimary new + reference: ::@extensionType::A::@constructor::new + firstFragment: #F4 + isExtensionTypeMember isOriginDeclaration new + reference: ::@extensionType::A::@constructor::new#1 + firstFragment: #F5 + getters + isExtensionTypeMember isOriginVariable + reference: ::@extensionType::A::@getter::#1 + firstFragment: #F3 + returnType: dynamic + variable: ::@extensionType::A::@field::#0 +'''); + } + + test_extensionType_augmentation_chain_noIntroductoryDeclaration_staticField() async { + var library = await buildLibrary(r''' +augment extension type A { + static int foo = 0; +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + extensionTypes + #F1 isAugmentation extension type A (nameOffset:23) (firstTokenOffset:0) (offset:23) + element: ::@extensionType::A + fields + #F2 hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@field::#0 + inducedGetter: #F3 + #F4 hasInitializer isOriginDeclaration isStatic foo (nameOffset:40) (firstTokenOffset:40) (offset:40) + element: ::@extensionType::A::@field::foo + inducedGetter: #F5 + inducedSetter: #F6 + constructors + #F7 isConst isOriginExtensionTypeRecovery isPrimary new (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@constructor::new + typeName: A + getters + #F3 isCompleteDeclaration isOriginVariable (nameOffset:) (firstTokenOffset:) (offset:23) + element: ::@extensionType::A::@getter::#1 + inducingVariable: #F2 + #F5 isCompleteDeclaration isOriginVariable isStatic foo (nameOffset:) (firstTokenOffset:) (offset:40) + element: ::@extensionType::A::@getter::foo + inducingVariable: #F4 + setters + #F6 isCompleteDeclaration isOriginVariable isStatic foo (nameOffset:) (firstTokenOffset:) (offset:40) + element: ::@extensionType::A::@setter::foo + inducingVariable: #F4 + formalParameters + #F8 requiredPositional value (nameOffset:) (firstTokenOffset:) (offset:40) + element: ::@extensionType::A::@setter::foo::@formalParameter::value + extensionTypes + isSimplyBounded extension type A + reference: ::@extensionType::A + firstFragment: #F1 + representation: ::@extensionType::A::@field::#0 + primaryConstructor: ::@extensionType::A::@constructor::new + typeErasure: dynamic + fields + hasImplicitType isFinal isOriginExtensionTypeRecoveryRepresentation + reference: ::@extensionType::A::@field::#0 + firstFragment: #F2 + type: dynamic + getter: ::@extensionType::A::@getter::#1 + hasInitializer isOriginDeclaration isStatic foo + reference: ::@extensionType::A::@field::foo + firstFragment: #F4 + type: int + getter: ::@extensionType::A::@getter::foo + setter: ::@extensionType::A::@setter::foo + constructors + isConst isExtensionTypeMember isOriginExtensionTypeRecovery isPrimary new + reference: ::@extensionType::A::@constructor::new + firstFragment: #F7 + getters + isExtensionTypeMember isOriginVariable + reference: ::@extensionType::A::@getter::#1 + firstFragment: #F3 + returnType: dynamic + variable: ::@extensionType::A::@field::#0 + isExtensionTypeMember isOriginVariable isStatic foo + reference: ::@extensionType::A::@getter::foo + firstFragment: #F5 + returnType: int + variable: ::@extensionType::A::@field::foo + setters + isExtensionTypeMember isOriginVariable isStatic foo + reference: ::@extensionType::A::@setter::foo + firstFragment: #F6 + formalParameters + #E0 requiredPositional value + firstFragment: #F8 + type: int + returnType: void + variable: ::@extensionType::A::@field::foo +'''); + } + test_extensionType_augmentation_chain_twoDeclarations() async { var library = await buildLibrary(r''' extension type A(int it) {} diff --git a/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart index a0fde2d2684..107b3d8ea04 100644 --- a/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart +++ b/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart @@ -455,7 +455,7 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor { @override void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) { computer._addRegionForFragment( - node.primaryConstructor.typeName, + node.namePart.typeName, node.declaredFragment, ); super.visitExtensionTypeDeclaration(node); diff --git a/pkg/linter/lib/src/ast.dart b/pkg/linter/lib/src/ast.dart index c34b72055c6..1e1b4d0a041 100644 --- a/pkg/linter/lib/src/ast.dart +++ b/pkg/linter/lib/src/ast.dart @@ -85,7 +85,7 @@ SyntacticEntity getNodeToAnnotate(AstNode node) { } else if (node is VariableDeclaration) { return node.name; } else if (node is ExtensionTypeDeclaration) { - return node.primaryConstructor.typeName; + return node.namePart.typeName; } assert(false, "Unaccounted for node type: '${node.runtimeType}'"); return node; diff --git a/pkg/linter/lib/src/extensions.dart b/pkg/linter/lib/src/extensions.dart index 60456134666..ab9ca988bdb 100644 --- a/pkg/linter/lib/src/extensions.dart +++ b/pkg/linter/lib/src/extensions.dart @@ -53,8 +53,7 @@ extension AstNodeExtension on AstNode { ClassDeclaration() => parent.namePart.typeName.isPrivate, EnumDeclaration() => parent.namePart.typeName.isPrivate, ExtensionDeclaration() => parent.name == null || parent.name.isPrivate, - ExtensionTypeDeclaration() => - parent.primaryConstructor.typeName.isPrivate, + ExtensionTypeDeclaration() => parent.namePart.typeName.isPrivate, MixinDeclaration() => parent.name.isPrivate, _ => false, }; diff --git a/pkg/linter/lib/src/rules/avoid_shadowing_type_parameters.dart b/pkg/linter/lib/src/rules/avoid_shadowing_type_parameters.dart index 79c75f98527..175a0b11104 100644 --- a/pkg/linter/lib/src/rules/avoid_shadowing_type_parameters.dart +++ b/pkg/linter/lib/src/rules/avoid_shadowing_type_parameters.dart @@ -129,7 +129,7 @@ class _Visitor extends SimpleAstVisitor { } else if (parent is ExtensionTypeDeclaration) { _checkForShadowing( typeParameters, - parent.primaryConstructor.typeParameters, + parent.namePart.typeParameters, 'extension type', ); } else if (parent is MethodDeclaration) { diff --git a/pkg/linter/lib/src/rules/camel_case_types.dart b/pkg/linter/lib/src/rules/camel_case_types.dart index c9307532e7c..fc2675ec3ac 100644 --- a/pkg/linter/lib/src/rules/camel_case_types.dart +++ b/pkg/linter/lib/src/rules/camel_case_types.dart @@ -75,7 +75,7 @@ class _Visitor extends SimpleAstVisitor { void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) { if (node.isAugmentation) return; - check(node.primaryConstructor.typeName); + check(node.namePart.typeName); } @override diff --git a/pkg/linter/lib/src/rules/library_private_types_in_public_api.dart b/pkg/linter/lib/src/rules/library_private_types_in_public_api.dart index 17c2cd62b84..913e58f467f 100644 --- a/pkg/linter/lib/src/rules/library_private_types_in_public_api.dart +++ b/pkg/linter/lib/src/rules/library_private_types_in_public_api.dart @@ -93,17 +93,19 @@ class Validator extends SimpleAstVisitor { @override void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) { - if (Identifier.isPrivateName(node.primaryConstructor.typeName.lexeme)) { + var namePart = node.namePart; + if (Identifier.isPrivateName(namePart.typeName.lexeme)) { return; } - node.primaryConstructor.typeParameters?.accept(this); + namePart.typeParameters?.accept(this); - for (var formalParameter - in node.primaryConstructor.formalParameters.parameters) { - if (formalParameter is RegularFormalParameter) { - var name = formalParameter.name; - if (name != null && !Identifier.isPrivateName(name.lexeme)) { - formalParameter.type?.accept(this); + if (namePart is PrimaryConstructorDeclaration) { + for (var formalParameter in namePart.formalParameters.parameters) { + if (formalParameter is RegularFormalParameter) { + var name = formalParameter.name; + if (name != null && !Identifier.isPrivateName(name.lexeme)) { + formalParameter.type?.accept(this); + } } } } diff --git a/pkg/linter/lib/src/rules/non_constant_identifier_names.dart b/pkg/linter/lib/src/rules/non_constant_identifier_names.dart index f0cfe484d80..a5a354bd2bb 100644 --- a/pkg/linter/lib/src/rules/non_constant_identifier_names.dart +++ b/pkg/linter/lib/src/rules/non_constant_identifier_names.dart @@ -89,7 +89,9 @@ class _Visitor extends SimpleAstVisitor { @override void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) { - checkIdentifier(node.primaryConstructor.constructorName?.name); + if (node.namePart case PrimaryConstructorDeclaration primaryConstructor) { + checkIdentifier(primaryConstructor.constructorName?.name); + } } @override diff --git a/pkg/linter/lib/src/rules/prefer_constructors_over_static_methods.dart b/pkg/linter/lib/src/rules/prefer_constructors_over_static_methods.dart index 62c95f2c4d2..a34270d07fa 100644 --- a/pkg/linter/lib/src/rules/prefer_constructors_over_static_methods.dart +++ b/pkg/linter/lib/src/rules/prefer_constructors_over_static_methods.dart @@ -87,7 +87,7 @@ class _Visitor extends SimpleAstVisitor { extension on AstNode? { InterfaceType? typeToCheckOrNull() => switch (this) { ExtensionTypeDeclaration e => - e.primaryConstructor.typeParameters == null + e.namePart.typeParameters == null ? e.declaredFragment?.element.thisType : null, ClassDeclaration c => diff --git a/pkg/linter/lib/src/rules/public_member_api_docs.dart b/pkg/linter/lib/src/rules/public_member_api_docs.dart index b3d5fbb6c9d..13303909068 100644 --- a/pkg/linter/lib/src/rules/public_member_api_docs.dart +++ b/pkg/linter/lib/src/rules/public_member_api_docs.dart @@ -215,7 +215,7 @@ class _Visitor extends SimpleAstVisitor { @override void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) { if (node.declaredFragment?.element == null) return; - _visitMembers(node, node.primaryConstructor.typeName, node.body.members); + _visitMembers(node, node.namePart.typeName, node.body.members); } @override diff --git a/pkg/linter/lib/src/rules/unnecessary_constructor_name.dart b/pkg/linter/lib/src/rules/unnecessary_constructor_name.dart index bc90fa89c21..eba42df2ec0 100644 --- a/pkg/linter/lib/src/rules/unnecessary_constructor_name.dart +++ b/pkg/linter/lib/src/rules/unnecessary_constructor_name.dart @@ -52,9 +52,12 @@ class _Visitor extends SimpleAstVisitor { return; } var parent = node.parent?.parent; - if (parent is ExtensionTypeDeclaration && - parent.primaryConstructor.constructorName == null) { - return; + if (parent is ExtensionTypeDeclaration) { + var namePart = parent.namePart; + if (namePart is PrimaryConstructorDeclaration && + namePart.constructorName == null) { + return; + } } _check(node.name); diff --git a/pkg/linter/lib/src/rules/unreachable_from_main.dart b/pkg/linter/lib/src/rules/unreachable_from_main.dart index 28e01013229..cf7e7b72f9a 100644 --- a/pkg/linter/lib/src/rules/unreachable_from_main.dart +++ b/pkg/linter/lib/src/rules/unreachable_from_main.dart @@ -718,7 +718,7 @@ extension on Declaration { var name = self.name; return name?.lexeme ?? 'the unnamed extension'; case ExtensionTypeDeclaration(): - return self.primaryConstructor.typeName.lexeme; + return self.namePart.typeName.lexeme; case FunctionDeclaration(): return self.name.lexeme; case MethodDeclaration():