diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index b71b88ccbba..f2d467159b1 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml @@ -255,6 +255,10 @@ augmentation_type_parameter_name: We could rename the type parameter, this is purely local operation. augmentation_without_declaration: status: noFix +augmentation_without_getter_declaration: + status: needsEvaluation +augmentation_without_setter_declaration: + status: needsEvaluation augmented_expression_is_not_setter: status: noFix augmented_expression_is_setter: diff --git a/pkg/analyzer/lib/src/diagnostic/diagnostic.g.dart b/pkg/analyzer/lib/src/diagnostic/diagnostic.g.dart index 86d8f99d2d4..6e46cb51488 100644 --- a/pkg/analyzer/lib/src/diagnostic/diagnostic.g.dart +++ b/pkg/analyzer/lib/src/diagnostic/diagnostic.g.dart @@ -1035,6 +1035,44 @@ const DiagnosticWithoutArguments augmentationWithoutDeclaration = expectedTypes: [], ); +/// Parameters: +/// String name: the name of the getter +const DiagnosticWithArguments< + LocatableDiagnostic Function({required String name}) +> +augmentationWithoutGetterDeclaration = DiagnosticWithArguments( + name: 'augmentation_without_declaration', + problemMessage: + "This augmentation induces a getter, but no getter declaration named '{0}' " + "exists to augment.", + correctionMessage: + "Try changing the augmentation to match an existing getter " + "declaration.", + type: DiagnosticType.COMPILE_TIME_ERROR, + uniqueName: 'augmentation_without_getter_declaration', + withArguments: _withArgumentsAugmentationWithoutGetterDeclaration, + expectedTypes: [ExpectedType.string], +); + +/// Parameters: +/// String name: the name of the setter +const DiagnosticWithArguments< + LocatableDiagnostic Function({required String name}) +> +augmentationWithoutSetterDeclaration = DiagnosticWithArguments( + name: 'augmentation_without_declaration', + problemMessage: + "This augmentation induces a setter, but no setter declaration named '{0}' " + "exists to augment.", + correctionMessage: + "Try changing the augmentation to match an existing setter " + "declaration.", + type: DiagnosticType.COMPILE_TIME_ERROR, + uniqueName: 'augmentation_without_setter_declaration', + withArguments: _withArgumentsAugmentationWithoutSetterDeclaration, + expectedTypes: [ExpectedType.string], +); + /// No parameters. const DiagnosticWithoutArguments augmentedExpressionIsNotSetter = DiagnosticWithoutArgumentsImpl( @@ -18411,6 +18449,22 @@ LocatableDiagnostic _withArgumentsAugmentationReturnTypeMismatch({ ]); } +LocatableDiagnostic _withArgumentsAugmentationWithoutGetterDeclaration({ + required String name, +}) { + return LocatableDiagnosticImpl(diag.augmentationWithoutGetterDeclaration, [ + name, + ]); +} + +LocatableDiagnostic _withArgumentsAugmentationWithoutSetterDeclaration({ + required String name, +}) { + return LocatableDiagnosticImpl(diag.augmentationWithoutSetterDeclaration, [ + name, + ]); +} + LocatableDiagnostic _withArgumentsAugmentedExpressionNotOperator({ required String operator, }) { diff --git a/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart b/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart index 9e23369510a..75a8c249b7e 100644 --- a/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart +++ b/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart @@ -79,6 +79,8 @@ const List diagnosticCodeValues = [ diag.augmentationTypeParameterCount, diag.augmentationTypeParameterName, diag.augmentationWithoutDeclaration, + diag.augmentationWithoutGetterDeclaration, + diag.augmentationWithoutSetterDeclaration, diag.augmentedExpressionIsNotSetter, diag.augmentedExpressionIsSetter, diag.augmentedExpressionNotOperator, diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 4d9987c6176..7bfb7b84c37 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -1034,10 +1034,14 @@ class ErrorVerifier extends RecursiveAstVisitor @override void visitFieldDeclaration(covariant FieldDeclarationImpl node) { - if (node.augmentKeyword case var augmentKeyword?) { + if (node.augmentKeyword != null) { for (var variable in node.fields.variables) { - var declaredFragment = variable.declaredFragment!; - _checkAugmentationWithoutDeclaration(augmentKeyword, declaredFragment); + var declaredFragment = variable.declaredFragment! as FieldFragmentImpl; + _checkAugmentationWithoutDeclaration(variable.name, declaredFragment); + _checkAugmentationWithoutDeclarationForInducedAccessors( + variable.name, + declaredFragment, + ); } } @@ -1993,10 +1997,15 @@ class ErrorVerifier extends RecursiveAstVisitor ) { var variableList = node.variables; - if (node.augmentKeyword case var augmentKeyword?) { + if (node.augmentKeyword != null) { for (var variable in variableList.variables) { - var declaredFragment = variable.declaredFragment!; - _checkAugmentationWithoutDeclaration(augmentKeyword, declaredFragment); + var declaredFragment = + variable.declaredFragment! as TopLevelVariableFragmentImpl; + _checkAugmentationWithoutDeclaration(variable.name, declaredFragment); + _checkAugmentationWithoutDeclarationForInducedAccessors( + variable.name, + declaredFragment, + ); } } @@ -2125,10 +2134,10 @@ class ErrorVerifier extends RecursiveAstVisitor } void _checkAugmentationWithoutDeclaration( - Token? augmentKeyword, + Token? errorToken, FragmentImpl fragment, ) { - if (augmentKeyword != null) { + if (errorToken != null) { if (fragment.previousFragment == null) { var element = fragment.element; var previousFragmentOfDifferentKind = @@ -2142,7 +2151,7 @@ class ErrorVerifier extends RecursiveAstVisitor "The declaration being augmented.", ), ]) - .at(augmentKeyword), + .at(errorToken), ); case FragmentImpl previousFragment: var previousElement = previousFragment.element; @@ -2157,17 +2166,71 @@ class ErrorVerifier extends RecursiveAstVisitor "The declaration being augmented.", ), ]) - .at(augmentKeyword), + .at(errorToken), ); case null: diagnosticReporter.report( - diag.augmentationWithoutDeclaration.at(augmentKeyword), + diag.augmentationWithoutDeclaration.at(errorToken), ); } } } } + void _checkAugmentationWithoutDeclarationForInducedAccessors( + Token variableName, + PropertyInducingFragmentImpl fragment, + ) { + var previousFragment = fragment.previousFragment; + + // Already reported by `_checkAugmentationWithoutDeclaration`. + if (previousFragment == null) { + return; + } + + if (fragment.inducedGetter case var inducedGetter?) { + if (inducedGetter.previousFragment == null) { + var setterFragment = + fragment.inducedSetter?.previousFragment ?? + fragment.element.setter?.lastFragment; + var contextMessage = + setterFragment?.contextMessageAt( + "The corresponding setter is declared here.", + ) ?? + previousFragment.contextMessageAt( + "The corresponding setter is induced by this declaration.", + ); + diagnosticReporter.report( + diag.augmentationWithoutGetterDeclaration + .withArguments(name: variableName.lexeme) + .withContextMessages([?contextMessage]) + .at(variableName), + ); + } + } + + if (fragment.inducedSetter case var inducedSetter?) { + if (inducedSetter.previousFragment == null) { + var getterFragment = + fragment.inducedGetter?.previousFragment ?? + fragment.element.getter?.lastFragment; + var contextMessage = + getterFragment?.contextMessageAt( + "The corresponding getter is declared here.", + ) ?? + previousFragment.contextMessageAt( + "The corresponding getter is induced by this declaration.", + ); + diagnosticReporter.report( + diag.augmentationWithoutSetterDeclaration + .withArguments(name: variableName.lexeme) + .withContextMessages([?contextMessage]) + .at(variableName), + ); + } + } + } + /// Checks the class for problems with the superclass, mixins, or implemented /// interfaces. /// diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml index a05362d8658..1d58f153cca 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -1869,6 +1869,24 @@ CompileTimeErrorCode: problemMessage: The declaration being augmented doesn't exist. correctionMessage: Try changing the augmentation to match an existing declaration. hasPublishedDocs: false + augmentationWithoutGetterDeclaration: + type: compileTimeError + parameters: + String name: the name of the getter + sharedName: augmentationWithoutDeclaration + experiment: augmentations + problemMessage: "This augmentation induces a getter, but no getter declaration named '#name' exists to augment." + correctionMessage: Try changing the augmentation to match an existing getter declaration. + hasPublishedDocs: false + augmentationWithoutSetterDeclaration: + type: compileTimeError + parameters: + String name: the name of the setter + sharedName: augmentationWithoutDeclaration + experiment: augmentations + problemMessage: "This augmentation induces a setter, but no setter declaration named '#name' exists to augment." + correctionMessage: Try changing the augmentation to match an existing setter declaration. + hasPublishedDocs: false augmentationOfMixinApplicationClass: type: compileTimeError parameters: none 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 54d6dfd1599..e3c0943751a 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 @@ -158,7 +158,7 @@ class A { } augment class A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a field. } '''); @@ -281,7 +281,7 @@ class A { } augment class A { augment static int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a constructor with a field. } '''); @@ -296,7 +296,7 @@ class A { } augment class A { augment static int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a method with a field. } '''); @@ -528,7 +528,8 @@ class A {} // ^ // [context 1] The declaration being augmented. augment int A = 0; -// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a class with a top level variable. +// ^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a class with a top level variable. '''); } @@ -538,7 +539,8 @@ void foo() {} // ^^^ // [context 1] The declaration being augmented. augment int foo = 0; -// [diag.augmentationOfDifferentDeclarationKind][column 1][length 7][context 1] Can't augment a function with a top level variable. +// ^^^ +// [diag.augmentationOfDifferentDeclarationKind][context 1] Can't augment a function with a top level variable. '''); } } 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 a72972dd8b9..aea7086f3f3 100644 --- a/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/augmentation_without_declaration_test.dart @@ -77,7 +77,7 @@ class A {} augment class A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -91,7 +91,7 @@ class A { augment class A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -109,6 +109,54 @@ augment class A { '''); } + test_class_instanceField_augments_instanceField_final() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + final int foo = 0; +// ^^^ +// [context 1] The corresponding getter is induced by this declaration. +} + +augment class A { + augment int foo = 1; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. +} +'''); + } + + test_class_instanceField_augments_instanceGetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. +} + +augment class A { + augment int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. +} +'''); + } + + test_class_instanceField_augments_instanceSetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. +} + +augment class A { + augment int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. +} +'''); + } + test_class_instanceField_augments_staticField() async { await resolveTestCodeWithDiagnostics(r''' class A { @@ -116,7 +164,7 @@ class A { } augment class A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -129,7 +177,7 @@ class A { } augment class A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -142,7 +190,7 @@ class A { } augment class A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -155,12 +203,52 @@ class A { } augment class A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); } + test_class_instanceField_final_augments_instanceField_final() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + final int foo = 0; +} + +augment class A { + augment final int foo = 1; +} +'''); + } + + test_class_instanceField_final_augments_instanceGetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + int get foo => 0; +} + +augment class A { + augment final int foo = 1; +} +'''); + } + + test_class_instanceField_final_augments_instanceSetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. +} + +augment class A { + augment final int foo = 1; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. +} +'''); + } + test_class_instanceGetter() async { await resolveTestCodeWithDiagnostics(r''' class A {} @@ -413,7 +501,7 @@ class A {} augment class A { augment static int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -426,9 +514,8 @@ class A { } augment class A { augment static int foo = 0; -//^^^^^^^ -// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // ^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } '''); @@ -441,9 +528,8 @@ class A { } augment class A { augment static int foo = 0; -//^^^^^^^ -// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // ^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } '''); @@ -456,9 +542,8 @@ class A { } augment class A { augment static int foo = 0; -//^^^^^^^ -// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // ^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } '''); @@ -471,14 +556,113 @@ class A { } augment class A { augment static int foo = 0; -//^^^^^^^ -// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // ^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. // [diag.conflictingStaticAndInstance] Class 'A' can't define static member 'foo' and have instance member 'A.foo' with the same name. } '''); } + test_class_staticField_augments_staticField() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + static int foo = 0; +} + +augment class A { + augment static int foo = 1; +} +'''); + } + + test_class_staticField_augments_staticField_final() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + static final int foo = 0; +// ^^^ +// [context 1] The corresponding getter is induced by this declaration. +} + +augment class A { + augment static int foo = 1; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. +} +'''); + } + + test_class_staticField_augments_staticGetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + static int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. +} + +augment class A { + augment static int foo = 1; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. +} +'''); + } + + test_class_staticField_augments_staticSetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + static set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. +} + +augment class A { + augment static int foo = 1; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. +} +'''); + } + + test_class_staticField_final_augments_staticField_final() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + static final int foo = 0; +} + +augment class A { + augment static final int foo = 1; +} +'''); + } + + test_class_staticField_final_augments_staticGetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + static int get foo => 0; +} + +augment class A { + augment static final int foo = 1; +} +'''); + } + + test_class_staticField_final_augments_staticSetter() async { + await resolveTestCodeWithDiagnostics(r''' +class A { + static set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. +} + +augment class A { + augment static final int foo = 1; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. +} +'''); + } + test_class_staticGetter() async { await resolveTestCodeWithDiagnostics(r''' class A {} @@ -728,7 +912,7 @@ enum A { augment enum A {; augment final int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -890,7 +1074,7 @@ mixin A {} augment mixin A { augment int foo = 0; -//^^^^^^^ +// ^^^ // [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. } '''); @@ -973,10 +1157,93 @@ augment set foo(int _) {} '''); } + test_topLevel_variable() async { + await resolveTestCodeWithDiagnostics(r''' +augment int foo = 0; +// ^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +'''); + } + + test_topLevel_variable_augments_getter() async { + await resolveTestCodeWithDiagnostics(r''' +int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. + +augment int foo = 1; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. +'''); + } + + test_topLevel_variable_augments_setter() async { + await resolveTestCodeWithDiagnostics(r''' +set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. + +augment int foo = 1; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. +'''); + } + + test_topLevel_variable_augments_variable() async { + await resolveTestCodeWithDiagnostics(r''' +int foo = 0; + +augment int foo = 1; +'''); + } + + test_topLevel_variable_augments_variable_final() async { + await resolveTestCodeWithDiagnostics(r''' +final int foo = 0; +// ^^^ +// [context 1] The corresponding getter is induced by this declaration. + +augment int foo = 1; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. +'''); + } + + test_topLevel_variable_final_augments_getter() async { + await resolveTestCodeWithDiagnostics(r''' +int get foo => 0; + +augment final int foo = 1; +'''); + } + + test_topLevel_variable_final_augments_setter() async { + await resolveTestCodeWithDiagnostics(r''' +set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. + +augment final int foo = 1; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. +'''); + } + + test_topLevel_variable_final_augments_variable_final() async { + await resolveTestCodeWithDiagnostics(r''' +final int foo = 0; + +augment final int foo = 1; +'''); + } + test_topLevel_variable_multiple() async { await resolveTestCodeWithDiagnostics(r''' augment int foo = 0, bar = 0; -// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. +// ^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. +// ^^^ +// [diag.augmentationWithoutDeclaration] The declaration being augmented doesn't exist. '''); } @@ -985,22 +1252,8 @@ augment int foo = 0, bar = 0; int bar = 0; augment int foo = 1, bar = 2; -// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. -'''); - } - - test_topLevel_variable_single() async { - await resolveTestCodeWithDiagnostics(r''' -augment int foo = 0; -// [diag.augmentationWithoutDeclaration][column 1][length 7] The declaration being augmented doesn't exist. -'''); - } - - test_topLevel_variable_single_augments_variable() async { - await resolveTestCodeWithDiagnostics(r''' -int foo = 0; - -augment int foo = 1; +// ^^^ +// [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 6bcae9928a6..a4e951bc120 100644 --- a/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart +++ b/pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart @@ -156,10 +156,14 @@ class C { await resolveTestCodeWithDiagnostics(r''' abstract class C { int get foo; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment abstract class C { augment int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. } '''); } @@ -457,10 +461,14 @@ class A(var int _, var int _); await resolveTestCodeWithDiagnostics(r''' abstract class C { void set foo(int _); +// ^^^ +// [context 1] The corresponding setter is declared here. } augment abstract class C { augment int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); } @@ -673,10 +681,14 @@ class C { await resolveTestCodeWithDiagnostics(r''' class A { static int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment class A { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. } '''); } @@ -815,10 +827,14 @@ class C { await resolveTestCodeWithDiagnostics(r''' class A { static void set foo(_) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment class A { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); } @@ -1208,10 +1224,14 @@ enum E(final int _, final int _) { enum E { v; void set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment enum E {; augment final int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); } @@ -1403,10 +1423,14 @@ enum E { enum E { v; static int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment enum E {; augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. } '''); } @@ -1556,10 +1580,14 @@ enum E { enum E { v; static void set foo(_) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment enum E {; augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); } @@ -1671,11 +1699,14 @@ extension E on A { await resolveTestCodeWithDiagnostics(r''' extension E on int { int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment extension E { augment int foo = 0; // ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. // [diag.extensionDeclaresInstanceField] Extensions can't declare instance fields. } '''); @@ -1821,11 +1852,14 @@ extension E on A { await resolveTestCodeWithDiagnostics(r''' extension E on int { void set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment extension E { augment int foo = 0; // ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. // [diag.extensionDeclaresInstanceField] Extensions can't declare instance fields. } '''); @@ -1967,10 +2001,14 @@ extension E on A { await resolveTestCodeWithDiagnostics(r''' extension E on int { static int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment extension E { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. } '''); } @@ -2115,10 +2153,14 @@ extension E on A { await resolveTestCodeWithDiagnostics(r''' extension E on int { static void set foo(_) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment extension E { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); } @@ -2207,11 +2249,14 @@ class DuplicateDefinitionExtensionTypeTest extends PubPackageResolutionTest { await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment extension type E(int it) { augment int foo = 0; // ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. // [diag.extensionTypeDeclaresInstanceField] Extension types can't declare instance fields. } '''); @@ -2327,11 +2372,14 @@ extension type E(int it) { await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { void set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment extension type E(int it) { augment int foo = 0; // ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. // [diag.extensionTypeDeclaresInstanceField] Extension types can't declare instance fields. } '''); @@ -2437,10 +2485,14 @@ extension type E(int it) { await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment extension type E(int it) { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. } '''); } @@ -2523,10 +2575,14 @@ extension type E(int it) { await resolveTestCodeWithDiagnostics(r''' extension type E(int it) { static void set foo(_) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment extension type E(int it) { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); } @@ -2645,10 +2701,14 @@ mixin M { await resolveTestCodeWithDiagnostics(r''' mixin M { int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment mixin M { augment int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. } '''); } @@ -2759,10 +2819,14 @@ mixin M { await resolveTestCodeWithDiagnostics(r''' mixin M { void set foo(int _) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment mixin M { augment int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); } @@ -2867,10 +2931,14 @@ mixin M { await resolveTestCodeWithDiagnostics(r''' mixin M { static int get foo => 0; +// ^^^ +// [context 1] The corresponding getter is declared here. } augment mixin M { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutSetterDeclaration][context 1] This augmentation induces a setter, but no setter declaration named 'foo' exists to augment. } '''); } @@ -2953,10 +3021,14 @@ mixin M { await resolveTestCodeWithDiagnostics(r''' mixin M { static void set foo(_) {} +// ^^^ +// [context 1] The corresponding setter is declared here. } augment mixin M { augment static int foo = 0; +// ^^^ +// [diag.augmentationWithoutGetterDeclaration][context 1] This augmentation induces a getter, but no getter declaration named 'foo' exists to augment. } '''); }