Skip to content

Commit 47383da

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Update LUB for Null vs star.
As specified in dart-lang/language#700 Change-Id: I324841799a485600bf1ebfd54cd852465efac715 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126981 Reviewed-by: Mike Fairhurst <mfairhurst@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 5ff9a2e commit 47383da

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

pkg/analyzer/lib/src/generated/type_system.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,22 @@ class Dart2TypeSystem extends TypeSystem {
428428
}
429429
}
430430

431+
var T1_impl = T1 as TypeImpl;
432+
var T2_impl = T2 as TypeImpl;
433+
434+
var T1_nullability = T1_impl.nullabilitySuffix;
435+
var T2_nullability = T2_impl.nullabilitySuffix;
436+
431437
// UP(T1, T2) where NULL(T1)
432438
if (T1_isNull) {
433439
// * T2 if T2 is nullable
440+
// * T2* if Null <: T2 or T1 <: Object (that is, T1 or T2 is legacy)
434441
// * T2? otherwise
435442
if (isNullable(T2)) {
436443
return T2;
444+
} else if (T1_nullability == NullabilitySuffix.star ||
445+
T2_nullability == NullabilitySuffix.star) {
446+
return T2_impl.withNullability(NullabilitySuffix.star);
437447
} else {
438448
return makeNullable(T2);
439449
}
@@ -442,9 +452,13 @@ class Dart2TypeSystem extends TypeSystem {
442452
// UP(T1, T2) where NULL(T2)
443453
if (T2_isNull) {
444454
// * T1 if T1 is nullable
455+
// * T1* if Null <: T1 or T2 <: Object (that is, T1 or T2 is legacy)
445456
// * T1? otherwise
446457
if (isNullable(T1)) {
447458
return T1;
459+
} else if (T1_nullability == NullabilitySuffix.star ||
460+
T2_nullability == NullabilitySuffix.star) {
461+
return T1_impl.withNullability(NullabilitySuffix.star);
448462
} else {
449463
return makeNullable(T1);
450464
}
@@ -486,12 +500,6 @@ class Dart2TypeSystem extends TypeSystem {
486500
}
487501
}
488502

489-
var T1_impl = T1 as TypeImpl;
490-
var T2_impl = T2 as TypeImpl;
491-
492-
var T1_nullability = T1_impl.nullabilitySuffix;
493-
var T2_nullability = T2_impl.nullabilitySuffix;
494-
495503
// UP(T1*, T2*) = S* where S is UP(T1, T2)
496504
// UP(T1*, T2?) = S? where S is UP(T1, T2)
497505
// UP(T1?, T2*) = S? where S is UP(T1, T2)

pkg/analyzer/test/generated/type_system_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,20 +2348,17 @@ class LeastUpperBoundFunctionsTest extends BoundTestBase {
23482348

23492349
@reflectiveTest
23502350
class LeastUpperBoundTest extends BoundTestBase {
2351-
@FailingTest(reason: 'With new rules UP(Never*, T)=T?')
23522351
void test_bottom_function() {
23532352
_checkLeastUpperBound(neverStar, functionTypeStar(returnType: voidNone),
23542353
functionTypeStar(returnType: voidNone));
23552354
}
23562355

2357-
@FailingTest(reason: 'With new rules UP(Never*, T)=T?')
23582356
void test_bottom_interface() {
23592357
var A = class_(name: 'A');
23602358
var typeA = interfaceTypeStar(A);
23612359
_checkLeastUpperBound(neverStar, typeA, typeA);
23622360
}
23632361

2364-
@FailingTest(reason: 'With new rules UP(Never*, T)=T?')
23652362
void test_bottom_typeParam() {
23662363
var T = typeParameter('T');
23672364
var typeT = typeParameterTypeStar(T);

pkg/analyzer/test/src/dart/element/upper_lower_bound_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,23 +1774,23 @@ class UpperBoundTest extends _BoundsTestBase {
17741774

17751775
check(nullNone, intNone, intQuestion);
17761776
check(nullNone, intQuestion, intQuestion);
1777-
check(nullNone, intStar, intQuestion);
1777+
check(nullNone, intStar, intStar);
17781778

17791779
check(nullQuestion, intNone, intQuestion);
17801780
check(nullQuestion, intQuestion, intQuestion);
1781-
check(nullQuestion, intStar, intQuestion);
1781+
check(nullQuestion, intStar, intStar);
17821782

1783-
check(nullStar, intNone, intQuestion);
1783+
check(nullStar, intNone, intStar);
17841784
check(nullStar, intQuestion, intQuestion);
1785-
check(nullStar, intStar, intQuestion);
1785+
check(nullStar, intStar, intStar);
17861786

17871787
check(nullNone, listNone(intNone), listQuestion(intNone));
17881788
check(nullNone, listQuestion(intNone), listQuestion(intNone));
1789-
check(nullNone, listStar(intNone), listQuestion(intNone));
1789+
check(nullNone, listStar(intNone), listStar(intNone));
17901790

17911791
check(nullNone, futureOrNone(intNone), futureOrQuestion(intNone));
17921792
check(nullNone, futureOrQuestion(intNone), futureOrQuestion(intNone));
1793-
check(nullNone, futureOrStar(intNone), futureOrQuestion(intNone));
1793+
check(nullNone, futureOrStar(intNone), futureOrStar(intNone));
17941794

17951795
check(nullNone, futureOrNone(intQuestion), futureOrNone(intQuestion));
17961796
check(nullNone, futureOrStar(intQuestion), futureOrStar(intQuestion));

0 commit comments

Comments
 (0)