Skip to content

Commit

Permalink
[cfe] Deem all intersection types syntactically not nullable
Browse files Browse the repository at this point in the history
Closes #44362.

Bug: #44362
Change-Id: Id54de1848e6af1108956476e241bab5c0ed96a4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177124
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
  • Loading branch information
Dmitry Stefantsov authored and commit-bot@chromium.org committed Dec 29, 2020
1 parent 13b1af4 commit 0642e7a
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/front_end/testcases/nnbd/issue44362.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

foo<X>(X? x) {
if (x is int) {
bar(x);
}
}

bar<Y>(dynamic y) {}

main() {}
10 changes: 10 additions & 0 deletions pkg/front_end/testcases/nnbd/issue44362.dart.outline.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic
;
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic
;
static method main() → dynamic
;
11 changes: 11 additions & 0 deletions pkg/front_end/testcases/nnbd/issue44362.dart.strong.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
if(x is{ForNonNullableByDefault} core::int) {
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
}
}
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
static method main() → dynamic {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
if(x is{ForNonNullableByDefault} core::int) {
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
}
}
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
static method main() → dynamic {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo<X>(X? x) {}
bar<Y>(dynamic y) {}
main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bar<Y>(dynamic y) {}
foo<X>(X? x) {}
main() {}
11 changes: 11 additions & 0 deletions pkg/front_end/testcases/nnbd/issue44362.dart.weak.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
if(x is{ForNonNullableByDefault} core::int) {
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
}
}
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
static method main() → dynamic {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

static method foo<X extends core::Object? = dynamic>(self::foo::X? x) → dynamic {
if(x is{ForNonNullableByDefault} core::int) {
self::bar<dynamic>(x{self::foo::X? & core::int /* '?' & '!' = '!' */});
}
}
static method bar<Y extends core::Object? = dynamic>(dynamic y) → dynamic {}
static method main() → dynamic {}
4 changes: 4 additions & 0 deletions pkg/kernel/lib/type_algebra.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,10 @@ bool isTypeParameterTypeWithoutNullabilityMarker(
/// and Null are nullable, but aren't considered applications of the nullable
/// type constructor.
bool isNullableTypeConstructorApplication(DartType type) {
if (type is TypeParameterType && type.promotedBound != null) {
// Promoted types are never considered applications of ?.
return false;
}
return type.declaredNullability == Nullability.nullable &&
type is! DynamicType &&
type is! VoidType &&
Expand Down

0 comments on commit 0642e7a

Please sign in to comment.