From 4e1954fa0890a5b6474778ddd3cffefc03d781c5 Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Mon, 23 Mar 2020 17:24:43 +0000 Subject: [PATCH] [cfe] Infer loadLibrary return a non-nullable future Closes #41122 Change-Id: I1ca82e27cc73900e19369d152cec4f7a7621777b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140400 Commit-Queue: Johnni Winther Reviewed-by: Dmitry Stefantsov --- .../src/fasta/kernel/inference_visitor.dart | 4 ++-- .../testcases/nnbd/load_library.dart | 12 ++++++++++++ .../nnbd/load_library.dart.outline.expect | 7 +++++++ .../nnbd/load_library.dart.strong.expect | 19 +++++++++++++++++++ ...oad_library.dart.strong.transformed.expect | 19 +++++++++++++++++++ .../nnbd/load_library.dart.weak.expect | 19 +++++++++++++++++++ .../load_library.dart.weak.transformed.expect | 19 +++++++++++++++++++ .../testcases/text_serialization.status | 1 + 8 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 pkg/front_end/testcases/nnbd/load_library.dart create mode 100644 pkg/front_end/testcases/nnbd/load_library.dart.outline.expect create mode 100644 pkg/front_end/testcases/nnbd/load_library.dart.strong.expect create mode 100644 pkg/front_end/testcases/nnbd/load_library.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/load_library.dart.weak.expect create mode 100644 pkg/front_end/testcases/nnbd/load_library.dart.weak.transformed.expect diff --git a/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart b/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart index e88cca04105..8a1b8fd4af2 100644 --- a/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart +++ b/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart @@ -5684,7 +5684,7 @@ class InferenceVisitor ExpressionInferenceResult visitLoadLibrary( covariant LoadLibraryImpl node, DartType typeContext) { DartType inferredType = inferrer.typeSchemaEnvironment - .futureType(const DynamicType(), inferrer.library.nullable); + .futureType(const DynamicType(), inferrer.library.nonNullable); if (node.arguments != null) { FunctionType calleeType = new FunctionType([], inferredType, inferrer.library.nonNullable); @@ -5699,7 +5699,7 @@ class InferenceVisitor DartType inferredType = new FunctionType( [], inferrer.typeSchemaEnvironment - .futureType(const DynamicType(), inferrer.library.nullable), + .futureType(const DynamicType(), inferrer.library.nonNullable), inferrer.library.nonNullable); Expression replacement = new StaticGet(node.target) ..fileOffset = node.fileOffset; diff --git a/pkg/front_end/testcases/nnbd/load_library.dart b/pkg/front_end/testcases/nnbd/load_library.dart new file mode 100644 index 00000000000..95e2745518f --- /dev/null +++ b/pkg/front_end/testcases/nnbd/load_library.dart @@ -0,0 +1,12 @@ +// 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. + +import "dart:math" deferred as math; + +main() { + var v1 = math.loadLibrary(); + v1.then((_) {}); + var v2 = math.loadLibrary; + v2().then((_) {}); +} diff --git a/pkg/front_end/testcases/nnbd/load_library.dart.outline.expect b/pkg/front_end/testcases/nnbd/load_library.dart.outline.expect new file mode 100644 index 00000000000..69f8d219692 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/load_library.dart.outline.expect @@ -0,0 +1,7 @@ +library /*isNonNullableByDefault*/; +import self as self; + +import "dart:math" deferred as math; + +static method main() → dynamic + ; diff --git a/pkg/front_end/testcases/nnbd/load_library.dart.strong.expect b/pkg/front_end/testcases/nnbd/load_library.dart.strong.expect new file mode 100644 index 00000000000..92acca28640 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/load_library.dart.strong.expect @@ -0,0 +1,19 @@ +library /*isNonNullableByDefault*/; +import self as self; +import "dart:async" as asy; +import "dart:core" as core; + +import "dart:math" deferred as math; + +static method main() → dynamic { + asy::Future v1 = LoadLibrary(math); + v1.{asy::Future::then}((dynamic _) → core::Null? {}); + () → asy::Future v2 = #C1; + v2.call().{asy::Future::then}((dynamic _) → core::Null? {}); +} +static method _#loadLibrary_math() → asy::Future + return LoadLibrary(math); + +constants { + #C1 = tearoff self::_#loadLibrary_math +} diff --git a/pkg/front_end/testcases/nnbd/load_library.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/load_library.dart.strong.transformed.expect new file mode 100644 index 00000000000..92acca28640 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/load_library.dart.strong.transformed.expect @@ -0,0 +1,19 @@ +library /*isNonNullableByDefault*/; +import self as self; +import "dart:async" as asy; +import "dart:core" as core; + +import "dart:math" deferred as math; + +static method main() → dynamic { + asy::Future v1 = LoadLibrary(math); + v1.{asy::Future::then}((dynamic _) → core::Null? {}); + () → asy::Future v2 = #C1; + v2.call().{asy::Future::then}((dynamic _) → core::Null? {}); +} +static method _#loadLibrary_math() → asy::Future + return LoadLibrary(math); + +constants { + #C1 = tearoff self::_#loadLibrary_math +} diff --git a/pkg/front_end/testcases/nnbd/load_library.dart.weak.expect b/pkg/front_end/testcases/nnbd/load_library.dart.weak.expect new file mode 100644 index 00000000000..92acca28640 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/load_library.dart.weak.expect @@ -0,0 +1,19 @@ +library /*isNonNullableByDefault*/; +import self as self; +import "dart:async" as asy; +import "dart:core" as core; + +import "dart:math" deferred as math; + +static method main() → dynamic { + asy::Future v1 = LoadLibrary(math); + v1.{asy::Future::then}((dynamic _) → core::Null? {}); + () → asy::Future v2 = #C1; + v2.call().{asy::Future::then}((dynamic _) → core::Null? {}); +} +static method _#loadLibrary_math() → asy::Future + return LoadLibrary(math); + +constants { + #C1 = tearoff self::_#loadLibrary_math +} diff --git a/pkg/front_end/testcases/nnbd/load_library.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/load_library.dart.weak.transformed.expect new file mode 100644 index 00000000000..92acca28640 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/load_library.dart.weak.transformed.expect @@ -0,0 +1,19 @@ +library /*isNonNullableByDefault*/; +import self as self; +import "dart:async" as asy; +import "dart:core" as core; + +import "dart:math" deferred as math; + +static method main() → dynamic { + asy::Future v1 = LoadLibrary(math); + v1.{asy::Future::then}((dynamic _) → core::Null? {}); + () → asy::Future v2 = #C1; + v2.call().{asy::Future::then}((dynamic _) → core::Null? {}); +} +static method _#loadLibrary_math() → asy::Future + return LoadLibrary(math); + +constants { + #C1 = tearoff self::_#loadLibrary_math +} diff --git a/pkg/front_end/testcases/text_serialization.status b/pkg/front_end/testcases/text_serialization.status index 39f2fd1be61..b510974df63 100644 --- a/pkg/front_end/testcases/text_serialization.status +++ b/pkg/front_end/testcases/text_serialization.status @@ -1301,6 +1301,7 @@ nnbd/later: TextSerializationFailure nnbd/lhs_of_if_null: TextSerializationFailure nnbd/list_constructor: TextSerializationFailure nnbd/literal_from_opt_in: TextSerializationFailure +nnbd/load_library: TextSerializationFailure nnbd/member_inheritance_from_opt_in: TextSerializationFailure nnbd/member_inheritance_from_opt_out: TextSerializationFailure nnbd/messages_with_types_opt_in: TypeCheckError