Skip to content

Commit 9bffff6

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Fix exception in migration of ?? operator when the right hand side is a generic type
Change-Id: Ie372522f9493e2ccea8284f8583b0f43153adbbd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123884 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
1 parent ed19100 commit 9bffff6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
378378
rightType = rightOperand.accept(this);
379379
});
380380
var ifNullNode = NullabilityNode.forIfNotNull();
381-
expressionType = DecoratedType(node.staticType, ifNullNode);
381+
expressionType = _decorateUpperOrLowerBound(
382+
node, node.staticType, leftType, rightType, true,
383+
node: ifNullNode);
382384
_connect(
383385
rightType.node, expressionType.node, IfNullOrigin(source, node));
384386
} finally {

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,15 @@ int f(int i, int j) => i ?? j;
12011201
assertEdge(right, expression, guards: [left], hard: false);
12021202
}
12031203

1204+
test_binaryExpression_questionQuestion_genericReturnType() async {
1205+
await analyze('''
1206+
class C<E> {
1207+
C<E> operator +(C<E> c) => this;
1208+
}
1209+
C<int> f(C<int> i, C<int> j) => i ?? j;
1210+
''');
1211+
}
1212+
12041213
test_binaryExpression_right_dynamic() async {
12051214
await analyze('''
12061215
class C {

0 commit comments

Comments
 (0)