diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart index 203386b28daa..96853235bd8c 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -914,10 +914,22 @@ abstract class BodyBuilder extends ScopeListener void resolveRedirectingFactoryTargets() { for (StaticInvocation invocation in redirectingFactoryInvocations) { - // If the invocation was invalid, it has already been desugared into - // an exception throwing expression. There is nothing to resolve anymore. - if (invocation.parent == null) { - continue; + // If the invocation was invalid, it or its parent has already been + // desugared into an exception throwing expression. There is nothing to + // resolve anymore. Note that in the case where the invocation's parent + // was invalid, type inference won't reach the invocation node and won't + // set its inferredType field. If type inference is disabled, reach to + // the outtermost parent to check if the node is a dead code. + if (invocation.parent == null) continue; + if (_typeInferrer != null) { + if (invocation is FactoryConstructorInvocationJudgment && + invocation.inferredType == null) { + continue; + } + } else { + TreeNode parent = invocation.parent; + while (parent is! Component && parent != null) parent = parent.parent; + if (parent == null) continue; } Procedure initialTarget = invocation.target; diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart index 8e0413844324..bca9db51b654 100644 --- a/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart @@ -18,6 +18,7 @@ export 'package:kernel/ast.dart' Catch, CheckLibraryIsLoaded, Class, + Component, Constructor, ConstructorInvocation, ContinueSwitchStatement,