Skip to content

Commit 0642e7a

Browse files
Dmitry Stefantsovcommit-bot@chromium.org
Dmitry Stefantsov
authored andcommitted
[cfe] Deem all intersection types syntactically not nullable
Closes #44362. Bug: #44362 Change-Id: Id54de1848e6af1108956476e241bab5c0ed96a4b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177124 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Dmitry Stefantsov <[email protected]>
1 parent 13b1af4 commit 0642e7a

9 files changed

+77
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
foo<X>(X? x) {
6+
if (x is int) {
7+
bar(x);
8+
}
9+
}
10+
11+
bar<Y>(dynamic y) {}
12+
13+
main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic
6+
;
7+
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic
8+
;
9+
static method main() → dynamic
10+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
6+
if(x is{ForNonNullableByDefault} core::int) {
7+
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
8+
}
9+
}
10+
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
11+
static method main() → dynamic {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
6+
if(x is{ForNonNullableByDefault} core::int) {
7+
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
8+
}
9+
}
10+
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
11+
static method main() → dynamic {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo<X>(X? x) {}
2+
bar<Y>(dynamic y) {}
3+
main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bar<Y>(dynamic y) {}
2+
foo<X>(X? x) {}
3+
main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
6+
if(x is{ForNonNullableByDefault} core::int) {
7+
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
8+
}
9+
}
10+
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
11+
static method main() → dynamic {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
6+
if(x is{ForNonNullableByDefault} core::int) {
7+
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
8+
}
9+
}
10+
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
11+
static method main() → dynamic {}

pkg/kernel/lib/type_algebra.dart

+4
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,10 @@ bool isTypeParameterTypeWithoutNullabilityMarker(
10671067
/// and Null are nullable, but aren't considered applications of the nullable
10681068
/// type constructor.
10691069
bool isNullableTypeConstructorApplication(DartType type) {
1070+
if (type is TypeParameterType && type.promotedBound != null) {
1071+
// Promoted types are never considered applications of ?.
1072+
return false;
1073+
}
10701074
return type.declaredNullability == Nullability.nullable &&
10711075
type is! DynamicType &&
10721076
type is! VoidType &&

0 commit comments

Comments
 (0)