Skip to content

Commit

Permalink
[cfe] Assume invocations are dead if they aren't reached by type infe…
Browse files Browse the repository at this point in the history
…rence

Closes #36356

Bug: http://dartbug.com/36356
Change-Id: I8fdc50877ada3eaa608bd8b02d53dc975af4efd8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98355
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
  • Loading branch information
Dmitry Stefantsov authored and commit-bot@chromium.org committed Apr 2, 2019
1 parent d320f42 commit 71a3649
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,22 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>

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;
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export 'package:kernel/ast.dart'
Catch,
CheckLibraryIsLoaded,
Class,
Component,
Constructor,
ConstructorInvocation,
ContinueSwitchStatement,
Expand Down

0 comments on commit 71a3649

Please sign in to comment.