Fix exception thrown in ConditionalModification

Change-Id: I6e60bd74bc55cafca86a64a721455e0ed465a357
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106101
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
Brian Wilkerson 2019-06-14 17:13:37 +00:00 committed by commit-bot@chromium.org
parent a02d6de474
commit dcc85a6594
2 changed files with 18 additions and 2 deletions

View file

@ -33,7 +33,7 @@ class ConditionalModification extends PotentialModification {
discard,
_KeepNode(node.condition),
_KeepNode(node.thenStatement),
_KeepNode(node.elseStatement));
node.elseStatement == null ? null : _KeepNode(node.elseStatement));
} else {
throw new UnimplementedError('TODO(paulberry)');
}
@ -58,7 +58,7 @@ class ConditionalModification extends PotentialModification {
if (discard.keepTrue) {
keepNodes.add(thenStatement); // TODO(paulberry): test
}
if (discard.keepFalse) {
if (discard.keepFalse && elseStatement != null) {
keepNodes.add(elseStatement); // TODO(paulberry): test
}
// TODO(paulberry): test thoroughly

View file

@ -694,6 +694,22 @@ int get g => 0;
await _checkSingleFileChanges(content, expected);
}
test_ifStatement_nullCheck_noElse() async {
var content = '''
int f(int x) {
if (x == null) return 0;
return x;
}
''';
var expected = '''
int f(int x) {
if (x == null) return 0;
return x;
}
''';
await _checkSingleFileChanges(content, expected);
}
test_instanceCreation_noTypeArguments_noParameters() async {
var content = '''
void main() {