Skip to content

Commit 7df4402

Browse files
committed
Issue 38878. Update SuperContext for annotations.
[email protected] Bug: #38878 Change-Id: Ib2944fd60062fca0ec2899d83656cdc02b0a4a87 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125529 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent e34e734 commit 7df4402

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

pkg/analyzer/lib/src/generated/super_context.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import 'package:analyzer/dart/ast/ast.dart';
66

77
/// An indication of the kind of context in which a super expression was found.
88
class SuperContext {
9+
/// An indication that the super expression is in a context in which it is
10+
/// invalid because it is in an annotation.
11+
static const SuperContext annotation = SuperContext._('annotation');
12+
913
/// An indication that the super expression is in a context in which it is
1014
/// invalid because it is in an instance member of an extension.
1115
static const SuperContext extension = SuperContext._('extension');
@@ -25,7 +29,9 @@ class SuperContext {
2529
/// being used.
2630
factory SuperContext.of(SuperExpression expression) {
2731
for (AstNode node = expression; node != null; node = node.parent) {
28-
if (node is CompilationUnit) {
32+
if (node is Annotation) {
33+
return SuperContext.annotation;
34+
} else if (node is CompilationUnit) {
2935
return SuperContext.static;
3036
} else if (node is ConstructorDeclaration) {
3137
return node.factoryKeyword == null

pkg/analyzer/test/generated/invalid_code_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ part '${[for(var v = 0;;) v]}';
224224
''');
225225
}
226226

227+
test_fuzz_38878() async {
228+
// We should not attempt to resolve `super` in annotations.
229+
await _assertCanBeAnalyzed(r'''
230+
class C {
231+
@A(super.f())
232+
f(int x) {}
233+
}
234+
''');
235+
}
236+
227237
test_genericFunction_asTypeArgument_ofUnresolvedClass() async {
228238
await _assertCanBeAnalyzed(r'''
229239
C<int Function()> c;

0 commit comments

Comments
 (0)