Skip to content

Commit

Permalink
Fix crash for no flow in annotation.
Browse files Browse the repository at this point in the history
FAILURE: class=class<@((){x:
[NoSuchMethodError: The method 'labeledStatement_begin' was called on null.
Receiver: null
Tried calling: labeledStatement_begin(Instance of 'LabeledStatementImpl'), #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
flutter#1      FlowAnalysisHelper.labeledStatement_enter (package:analyzer/src/dart/resolver/flow_analysis_visitor.dart:196:10)
flutter#2      ResolverVisitor.visitLabeledStatement (package:analyzer/src/generated/resolver.dart:1636:20)
flutter#3      LabeledStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:6520:49)
flutter#4      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#5      BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1087:17)
flutter#6      ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1749:10)
flutter#7      UnifyingAstVisitor.visitBlock (package:analyzer/dart/ast/visitor.dart:3143:31)
flutter#8      ScopedVisitor.visitBlock.<anonymous closure> (package:analyzer/src/generated/resolver.dart:2473:13)
flutter#9      ScopedVisitor._withDeclaredLocals (package:analyzer/src/generated/resolver.dart:3067:8)
flutter#10     ScopedVisitor.visitBlock (package:analyzer/src/generated/resolver.dart:2472:5)
flutter#11     BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:1083:49)
flutter#12     BlockFunctionBodyImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1042:13)
flutter#13     ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1749:10)
flutter#14     UnifyingAstVisitor.visitBlockFunctionBody (package:analyzer/dart/ast/visitor.dart:3146:55)
flutter#15     ScopedVisitor.visitBlockFunctionBody (package:analyzer/src/generated/resolver.dart:2482:13)
flutter#16     ResolverVisitor.visitBlockFunctionBody (package:analyzer/src/generated/resolver.dart:957:13)
flutter#17     BlockFunctionBodyImpl.accept (package:analyzer/src/dart/ast/ast.dart:1038:49)
flutter#18     FunctionExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:5010:12)
flutter#19     FunctionExpressionResolver.resolve (package:analyzer/src/dart/resolver/function_expression_resolver.dart:65:10)
flutter#20     ResolverVisitor.visitFunctionExpression (package:analyzer/src/generated/resolver.dart:1460:37)
#21     FunctionExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:5004:49)
#22     ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#23     ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#24     AnnotationResolver.resolve (package:analyzer/src/dart/resolver/annotation_resolver.dart:35:21)
#25     ResolverVisitor.visitAnnotation (package:analyzer/src/generated/resolver.dart:823:30)
#26     AnnotationImpl.accept (package:analyzer/src/dart/ast/ast.dart:280:49)
#27     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#28     AnnotatedNodeImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:148:17)
#29     TypeParameterImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:10298:11)
#30     ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1749:10)
#31     UnifyingAstVisitor.visitTypeParameter (package:analyzer/dart/ast/visitor.dart:3475:47)
#32     TypeParameterImpl.accept (package:analyzer/src/dart/ast/ast.dart:10294:49)
#33     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#34     TypeParameterListImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:10346:21)
#35     ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1749:10)
#36     UnifyingAstVisitor.visitTypeParameterList (package:analyzer/dart/ast/visitor.dart:3478:55)
#37     TypeParameterListImpl.accept (package:analyzer/src/dart/ast/ast.dart:10342:49)
#38     ScopedVisitor.visitClassDeclarationInScope (package:analyzer/src/generated/resolver.dart:2533:26)
#39     ScopedVisitor.visitClassDeclaration (package:analyzer/src/generated/resolver.dart:2521:7)
#40     ResolverVisitor.visitClassDeclaration (package:analyzer/src/generated/resolver.dart:1015:13)
#41     ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:1536:49)
#42     ResolverVisitor.visitCompilationUnit (package:analyzer/src/generated/resolver.dart:1091:23)
#43     CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2134:49)
#44     LibraryAnalyzer._resolveFile (package:analyzer/src/dart/analysis/library_analyzer.dart:706:10)
#45     LibraryAnalyzer.analyzeSync.<anonymous closure> (package:analyzer/src/dart/analysis/library_analyzer.dart:139:7)

Change-Id: I13a10d2c127528aa9166e82a5ae535ddbbb8a022
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175943
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and [email protected] committed Dec 14, 2020
1 parent 05cce14 commit 57fa20a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ class FlowAnalysisHelper {
}

void labeledStatement_enter(LabeledStatement node) {
if (flow == null) return;

flow.labeledStatement_begin(node);
}

void labeledStatement_exit(LabeledStatement node) {
if (flow == null) return;

flow.labeledStatement_end();
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/test/generated/invalid_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ var v = <T>();
''');
}

test_inAnnotation_noFlow_labeledStatement() async {
await _assertCanBeAnalyzed('''
@A(() { label: })
typedef F = void Function();
''');
}

test_inDefaultValue_noFlow_ifExpression() async {
await _assertCanBeAnalyzed('''
typedef void F({a = [if (true) 0]});
Expand Down

0 comments on commit 57fa20a

Please sign in to comment.