Skip to content

Commit

Permalink
Augment. Report DECLARATION_NAMED_AUGMENTED_INSIDE_AUGMENTATION for D…
Browse files Browse the repository at this point in the history
…eclaredVariablePattern.

Change-Id: I819d03d0a8c58d1f54ec5637bce4d45ad2b91e83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366065
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed May 13, 2024
1 parent aac993f commit 02afdb9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4010,6 +4010,16 @@ class AstBuilder extends StackListener {
assert(_featureSet.isEnabled(Feature.patterns));
assert(variable.lexeme != '_');
var type = pop() as TypeAnnotationImpl?;

if (_enclosingDeclarationAugmentToken != null) {
if (variable.lexeme == 'augmented') {
errorReporter.errorReporter?.atToken(
variable,
ParserErrorCode.DECLARATION_NAMED_AUGMENTED_INSIDE_AUGMENTATION,
);
}
}

push(
DeclaredVariablePatternImpl(
keyword: keyword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,46 @@ augment class A {
]);
}

test_insideFunctionAugmentation_declaredVariablePattern_assignment() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
void f() {}
''');

await assertErrorsInCode('''
augment library 'a.dart';
augment void f() {
var (augmented,) = (0,);
}
''', [
error(ParserErrorCode.DECLARATION_NAMED_AUGMENTED_INSIDE_AUGMENTATION, 53,
9),
error(WarningCode.UNUSED_LOCAL_VARIABLE, 53, 9),
]);
}

test_insideFunctionAugmentation_declaredVariablePattern_match() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
void f() {}
''');

await assertErrorsInCode('''
augment library 'a.dart';
augment void f() {
if ((0,) case (var augmented,)) {}
}
''', [
error(ParserErrorCode.DECLARATION_NAMED_AUGMENTED_INSIDE_AUGMENTATION, 67,
9),
error(WarningCode.UNUSED_LOCAL_VARIABLE, 67, 9),
]);
}

test_insideFunctionAugmentation_formalParameter() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
Expand Down

0 comments on commit 02afdb9

Please sign in to comment.