diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart index 3467a0cd320b5..b580ddcc77a8c 100644 --- a/pkg/analyzer/lib/src/generated/resolver.dart +++ b/pkg/analyzer/lib/src/generated/resolver.dart @@ -1516,7 +1516,7 @@ class ResolverVisitor extends ScopedVisitor { CollectionElement thenElement = node.thenElement; if (_flowAnalysis != null) { - _flowAnalysis.flow.ifStatement_thenBegin(condition); + _flowAnalysis.flow?.ifStatement_thenBegin(condition); thenElement.accept(this); } else { _promoteManager.visitIfElement_thenElement( @@ -1556,7 +1556,7 @@ class ResolverVisitor extends ScopedVisitor { Statement thenStatement = node.thenStatement; if (_flowAnalysis != null) { - _flowAnalysis.flow.ifStatement_thenBegin(condition); + _flowAnalysis.flow?.ifStatement_thenBegin(condition); visitStatementInScope(thenStatement); nullSafetyDeadCodeVerifier?.flowEnd(thenStatement); } else { diff --git a/pkg/analyzer/test/generated/invalid_code_test.dart b/pkg/analyzer/test/generated/invalid_code_test.dart index 4464ab9d75953..21c3cc9f5c32f 100644 --- a/pkg/analyzer/test/generated/invalid_code_test.dart +++ b/pkg/analyzer/test/generated/invalid_code_test.dart @@ -395,6 +395,18 @@ var v = (); '''); } + test_inDefaultValue_noFlow_ifExpression() async { + await _assertCanBeAnalyzed(''' +typedef void F({a = [if (true) 0]}); +'''); + } + + test_inDefaultValue_noFlow_ifStatement() async { + await _assertCanBeAnalyzed(''' +typedef void F([a = () { if (true) 0; }]); +'''); + } + test_issue_40837() async { await _assertCanBeAnalyzed(''' class A {