From d690a0c7c4353e83e25423d05d5685e7c767efa1 Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Mon, 20 Apr 2020 07:03:55 +0000 Subject: [PATCH] [cfe] Handle nullability of typedefs Closes #41496 Closes #41498 Closes #41499 Closes #41501 Closes #41505 Change-Id: I425b6137f9ea41d01c95332ef1f7d43ca7afb5a6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143811 Reviewed-by: Dmitry Stefantsov Commit-Queue: Johnni Winther --- .dart_tool/package_config.json | 5 + .../src/fasta/builder/type_alias_builder.dart | 32 ++++--- .../fasta/dill/dill_type_alias_builder.dart | 2 +- .../test/spell_checking_list_tests.txt | 3 + pkg/front_end/testcases/nnbd/issue41496.dart | 15 +++ .../nnbd/issue41496.dart.outline.expect | 32 +++++++ .../nnbd/issue41496.dart.strong.expect | 33 +++++++ .../issue41496.dart.strong.transformed.expect | 33 +++++++ .../nnbd/issue41496.dart.weak.expect | 33 +++++++ .../issue41496.dart.weak.transformed.expect | 33 +++++++ .../testcases/nnbd/issue41496_lib.dart | 11 +++ pkg/front_end/testcases/nnbd/issue41496b.dart | 17 ++++ .../nnbd/issue41496b.dart.outline.expect | 36 ++++++++ .../nnbd/issue41496b.dart.strong.expect | 39 ++++++++ ...issue41496b.dart.strong.transformed.expect | 39 ++++++++ .../nnbd/issue41496b.dart.weak.expect | 39 ++++++++ .../issue41496b.dart.weak.transformed.expect | 39 ++++++++ .../testcases/nnbd/issue41496b_lib.dart | 15 +++ pkg/front_end/testcases/nnbd/issue41498.dart | 35 +++++++ .../nnbd/issue41498.dart.outline.expect | 34 +++++++ .../nnbd/issue41498.dart.strong.expect | 86 +++++++++++++++++ .../issue41498.dart.strong.transformed.expect | 86 +++++++++++++++++ .../nnbd/issue41498.dart.weak.expect | 86 +++++++++++++++++ .../issue41498.dart.weak.transformed.expect | 86 +++++++++++++++++ .../testcases/nnbd/issue41498_lib.dart | 36 ++++++++ pkg/front_end/testcases/nnbd/issue41498b.dart | 42 +++++++++ .../nnbd/issue41498b.dart.outline.expect | 38 ++++++++ .../nnbd/issue41498b.dart.strong.expect | 92 +++++++++++++++++++ ...issue41498b.dart.strong.transformed.expect | 92 +++++++++++++++++++ .../nnbd/issue41498b.dart.weak.expect | 92 +++++++++++++++++++ .../issue41498b.dart.weak.transformed.expect | 92 +++++++++++++++++++ .../testcases/nnbd/issue41498b_lib.dart | 35 +++++++ pkg/front_end/testcases/nnbd/issue41499.dart | 17 ++++ .../nnbd/issue41499.dart.outline.expect | 27 ++++++ .../nnbd/issue41499.dart.strong.expect | 57 ++++++++++++ .../issue41499.dart.strong.transformed.expect | 57 ++++++++++++ .../nnbd/issue41499.dart.weak.expect | 57 ++++++++++++ .../issue41499.dart.weak.transformed.expect | 57 ++++++++++++ .../testcases/nnbd/issue41499_lib.dart | 8 ++ pkg/front_end/testcases/nnbd/issue41499b.dart | 13 +++ .../nnbd/issue41499b.dart.outline.expect | 29 ++++++ .../nnbd/issue41499b.dart.strong.expect | 59 ++++++++++++ ...issue41499b.dart.strong.transformed.expect | 59 ++++++++++++ .../nnbd/issue41499b.dart.weak.expect | 59 ++++++++++++ .../issue41499b.dart.weak.transformed.expect | 59 ++++++++++++ .../testcases/nnbd/issue41499b_lib.dart | 15 +++ .../nonfunction_type_aliases/issue41501.dart | 21 +++++ .../issue41501.dart.outline.expect | 28 ++++++ .../issue41501.dart.strong.expect | 62 +++++++++++++ .../issue41501.dart.strong.transformed.expect | 62 +++++++++++++ .../issue41501.dart.weak.expect | 62 +++++++++++++ .../issue41501.dart.weak.transformed.expect | 62 +++++++++++++ .../issue41501_lib.dart | 21 +++++ .../nonfunction_type_aliases/test.options | 1 + .../testcases/text_serialization.status | 7 ++ tools/generate_package_config.dart | 1 + 56 files changed, 2274 insertions(+), 14 deletions(-) create mode 100644 pkg/front_end/testcases/nnbd/issue41496.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41496.dart.outline.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496.dart.strong.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496.dart.weak.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496_lib.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41496b.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41496b.dart.outline.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496b.dart.strong.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496b.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496b.dart.weak.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496b.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41496b_lib.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41498.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41498.dart.outline.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498.dart.strong.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498.dart.weak.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498_lib.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41498b.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41498b.dart.outline.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498b.dart.strong.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498b.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498b.dart.weak.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498b.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41498b_lib.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41499.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41499.dart.outline.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499.dart.strong.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499.dart.weak.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499_lib.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41499b.dart create mode 100644 pkg/front_end/testcases/nnbd/issue41499b.dart.outline.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499b.dart.strong.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499b.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499b.dart.weak.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499b.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/nnbd/issue41499b_lib.dart create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.outline.expect create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.expect create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.expect create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart create mode 100644 pkg/front_end/testcases/nonfunction_type_aliases/test.options diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index af00b66ccf7..9a6403f3d3a 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -262,6 +262,11 @@ "rootUri": "../pkg/front_end/testcases/nnbd", "packageUri": ".nonexisting/" }, + { + "name": "front_end_nonfunction_type_aliases", + "rootUri": "../pkg/front_end/testcases/nonfunction_type_aliases", + "packageUri": ".nonexisting/" + }, { "name": "frontend_server", "rootUri": "../pkg/frontend_server", diff --git a/pkg/front_end/lib/src/fasta/builder/type_alias_builder.dart b/pkg/front_end/lib/src/fasta/builder/type_alias_builder.dart index a852f46388c..7b267573ac9 100644 --- a/pkg/front_end/lib/src/fasta/builder/type_alias_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/type_alias_builder.dart @@ -79,7 +79,7 @@ class TypeAliasBuilder extends TypeDeclarationBuilderImpl { bool get fromDill => false; Typedef build(SourceLibraryBuilder libraryBuilder) { - typedef..type ??= buildThisType(libraryBuilder); + typedef..type ??= buildThisType(); TypeBuilder type = this.type; if (type is FunctionTypeBuilder) { @@ -146,7 +146,7 @@ class TypeAliasBuilder extends TypeDeclarationBuilderImpl { return result; } - DartType buildThisType(LibraryBuilder library) { + DartType buildThisType() { if (thisType != null) { if (identical(thisType, cyclicTypeAliasMarker)) { library.addProblem(templateCyclicTypedef.withArguments(name), @@ -181,7 +181,7 @@ class TypeAliasBuilder extends TypeDeclarationBuilderImpl { /// [arguments] have already been built. DartType buildTypesWithBuiltArguments(LibraryBuilder library, Nullability nullability, List arguments) { - DartType thisType = buildThisType(library); + DartType thisType = buildThisType(); if (const DynamicType() == thisType) return thisType; Nullability adjustedNullability = isNullAlias ? Nullability.nullable : nullability; @@ -248,26 +248,32 @@ class TypeAliasBuilder extends TypeDeclarationBuilderImpl { DartType buildType(LibraryBuilder library, NullabilityBuilder nullabilityBuilder, List arguments, [bool notInstanceContext]) { - DartType thisType = buildThisType(library); + DartType thisType = buildThisType(); if (thisType is InvalidType) return thisType; // TODO(dmitryas): Remove the following comment when FutureOr has its own // encoding and isn't represented as an InterfaceType. // The following won't work if the right-hand side of the typedef is a // FutureOr. - Nullability rhsNullability = thisType.nullability; + Nullability nullability; + if (isNullAlias) { + // Null is always nullable. + nullability = Nullability.nullable; + } else if (!parent.isNonNullableByDefault || + !library.isNonNullableByDefault) { + // The typedef is defined or used in an opt-out library so the nullability + // is based on the use site alone. + nullability = nullabilityBuilder.build(library); + } else { + nullability = uniteNullabilities( + thisType.nullability, nullabilityBuilder.build(library)); + } if (typedef.typeParameters.isEmpty && arguments == null) { - Nullability nullability = isNullAlias - ? Nullability.nullable - : nullabilityBuilder.build(library); - return thisType - .withNullability(uniteNullabilities(rhsNullability, nullability)); + return thisType.withNullability(nullability); } // Otherwise, substitute. return buildTypesWithBuiltArguments( - library, - uniteNullabilities(rhsNullability, nullabilityBuilder.build(library)), - buildTypeArguments(library, arguments)); + library, nullability, buildTypeArguments(library, arguments)); } TypeDeclarationBuilder _cachedUnaliasedDeclaration; diff --git a/pkg/front_end/lib/src/fasta/dill/dill_type_alias_builder.dart b/pkg/front_end/lib/src/fasta/dill/dill_type_alias_builder.dart index f13acd1b152..6a0691408df 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_type_alias_builder.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_type_alias_builder.dart @@ -45,7 +45,7 @@ class DillTypeAliasBuilder extends TypeAliasBuilder { } @override - DartType buildThisType(LibraryBuilder library) { + DartType buildThisType() { return thisType ??= typedef.type; } diff --git a/pkg/front_end/test/spell_checking_list_tests.txt b/pkg/front_end/test/spell_checking_list_tests.txt index 44f1f7775b5..95a7bb355ba 100644 --- a/pkg/front_end/test/spell_checking_list_tests.txt +++ b/pkg/front_end/test/spell_checking_list_tests.txt @@ -276,6 +276,9 @@ isolate isolates issue41210b issue41436c +issue41496b +issue41498b +issue41499b iter joo jumped diff --git a/pkg/front_end/testcases/nnbd/issue41496.dart b/pkg/front_end/testcases/nnbd/issue41496.dart new file mode 100644 index 00000000000..93d3769b124 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496.dart @@ -0,0 +1,15 @@ +// 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 "issue41496_lib.dart"; + +LegacyFoo f1; + +class C { + static LegacyFoo f2; +} + +main() { + new C(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41496.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue41496.dart.outline.expect new file mode 100644 index 00000000000..de2e711ad32 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496.dart.outline.expect @@ -0,0 +1,32 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496_lib.dart"; + +class C extends core::Object { + static field () → void f2; + synthetic constructor •() → self::C + ; +} +static field () → void f1; +static method main() → dynamic + ; + +library opted_out_lib; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic + ; diff --git a/pkg/front_end/testcases/nnbd/issue41496.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue41496.dart.strong.expect new file mode 100644 index 00000000000..5a1bc3137ce --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496.dart.strong.expect @@ -0,0 +1,33 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496_lib.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → self::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new self::C::•(); +} + +library opted_out_lib; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41496.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue41496.dart.strong.transformed.expect new file mode 100644 index 00000000000..5a1bc3137ce --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496.dart.strong.transformed.expect @@ -0,0 +1,33 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496_lib.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → self::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new self::C::•(); +} + +library opted_out_lib; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41496.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue41496.dart.weak.expect new file mode 100644 index 00000000000..5a1bc3137ce --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496.dart.weak.expect @@ -0,0 +1,33 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496_lib.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → self::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new self::C::•(); +} + +library opted_out_lib; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41496.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue41496.dart.weak.transformed.expect new file mode 100644 index 00000000000..5a1bc3137ce --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496.dart.weak.transformed.expect @@ -0,0 +1,33 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496_lib.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → self::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new self::C::•(); +} + +library opted_out_lib; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41496_lib.dart b/pkg/front_end/testcases/nnbd/issue41496_lib.dart new file mode 100644 index 00000000000..8950f0de811 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496_lib.dart @@ -0,0 +1,11 @@ +// 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. + +// @dart=2.6 + +library opted_out_lib; + +typedef void LegacyFoo(); + +test(LegacyFoo f) {} diff --git a/pkg/front_end/testcases/nnbd/issue41496b.dart b/pkg/front_end/testcases/nnbd/issue41496b.dart new file mode 100644 index 00000000000..4bafd01b73c --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496b.dart @@ -0,0 +1,17 @@ +// 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. + +// @dart=2.6 + +library opted_out_lib; + +import 'issue41496b_lib.dart' as opt_in; + +typedef void LegacyFoo(); + +test(LegacyFoo f) {} + +main() { + opt_in.main(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41496b.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue41496b.dart.outline.expect new file mode 100644 index 00000000000..e5969335ba4 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496b.dart.outline.expect @@ -0,0 +1,36 @@ +library opted_out_lib; +import self as self; + +import "org-dartlang-testcase:///issue41496b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic + ; +static method main() → dynamic + ; + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as self2; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496b.dart"; + +class C extends core::Object { + static field () → void f2; + synthetic constructor •() → self2::C + ; +} +static field () → void f1; +static method main() → dynamic + ; diff --git a/pkg/front_end/testcases/nnbd/issue41496b.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue41496b.dart.strong.expect new file mode 100644 index 00000000000..b70a566d271 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496b.dart.strong.expect @@ -0,0 +1,39 @@ +library opted_out_lib; +import self as self; +import "issue41496b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41496b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496b.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → iss::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new iss::C::•(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41496b.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue41496b.dart.strong.transformed.expect new file mode 100644 index 00000000000..b70a566d271 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496b.dart.strong.transformed.expect @@ -0,0 +1,39 @@ +library opted_out_lib; +import self as self; +import "issue41496b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41496b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496b.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → iss::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new iss::C::•(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41496b.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue41496b.dart.weak.expect new file mode 100644 index 00000000000..b70a566d271 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496b.dart.weak.expect @@ -0,0 +1,39 @@ +library opted_out_lib; +import self as self; +import "issue41496b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41496b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496b.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → iss::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new iss::C::•(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41496b.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue41496b.dart.weak.transformed.expect new file mode 100644 index 00000000000..b70a566d271 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496b.dart.weak.transformed.expect @@ -0,0 +1,39 @@ +library opted_out_lib; +import self as self; +import "issue41496b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41496b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:7:11: Error: Field 'f1' should be initialized because its type 'void Function()' doesn't allow null. +// LegacyFoo f1; +// ^^ +// +// pkg/front_end/testcases/nnbd/issue41496b_lib.dart:10:20: Error: Field 'f2' should be initialized because its type 'void Function()' doesn't allow null. +// static LegacyFoo f2; +// ^^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41496b.dart"; + +class C extends core::Object { + static field () → void f2 = null; + synthetic constructor •() → iss::C + : super core::Object::•() + ; +} +static field () → void f1; +static method main() → dynamic { + new iss::C::•(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41496b_lib.dart b/pkg/front_end/testcases/nnbd/issue41496b_lib.dart new file mode 100644 index 00000000000..06bf01a142f --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41496b_lib.dart @@ -0,0 +1,15 @@ +// 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 "issue41496b.dart"; + +LegacyFoo f1; + +class C { + static LegacyFoo f2; +} + +main() { + new C(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41498.dart b/pkg/front_end/testcases/nnbd/issue41498.dart new file mode 100644 index 00000000000..e6c1130291c --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498.dart @@ -0,0 +1,35 @@ +// 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 "issue41498_lib.dart"; + +class C { + static void test() { + LegacyFoo f; + + f.toString(); // error + } + + void test2() { + LegacyFoo f; + + f.toString(); // error + } +} + +test() { + LegacyFoo f; + + f.toString(); // error + + Function foo = () { + LegacyFoo f; + + f.toString(); // error + }; + C.test(); + new C().test2(); +} + +main() {} diff --git a/pkg/front_end/testcases/nnbd/issue41498.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue41498.dart.outline.expect new file mode 100644 index 00000000000..b4fdb094654 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498.dart.outline.expect @@ -0,0 +1,34 @@ +library /*isNonNullableByDefault*/; +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + ; + static method test() → void + ; + method test2() → void + ; +} +static method test() → dynamic + ; +static method main() → dynamic + ; + +library opted_out_lib; +import self as self2; +import "dart:core" as core; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self2::C* + ; + static method test() → void + ; + method test2() → void + ; +} +static method test() → dynamic + ; diff --git a/pkg/front_end/testcases/nnbd/issue41498.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue41498.dart.strong.expect new file mode 100644 index 00000000000..f2f0faaf3b1 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498.dart.strong.expect @@ -0,0 +1,86 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic {} + +library opted_out_lib; +import self as self2; +import "dart:core" as core; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self2::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self2::C::test(); + new self2::C::•().{self2::C::test2}(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41498.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue41498.dart.strong.transformed.expect new file mode 100644 index 00000000000..f2f0faaf3b1 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498.dart.strong.transformed.expect @@ -0,0 +1,86 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic {} + +library opted_out_lib; +import self as self2; +import "dart:core" as core; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self2::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self2::C::test(); + new self2::C::•().{self2::C::test2}(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41498.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue41498.dart.weak.expect new file mode 100644 index 00000000000..f2f0faaf3b1 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498.dart.weak.expect @@ -0,0 +1,86 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic {} + +library opted_out_lib; +import self as self2; +import "dart:core" as core; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self2::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self2::C::test(); + new self2::C::•().{self2::C::test2}(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41498.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue41498.dart.weak.transformed.expect new file mode 100644 index 00000000000..f2f0faaf3b1 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498.dart.weak.transformed.expect @@ -0,0 +1,86 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic {} + +library opted_out_lib; +import self as self2; +import "dart:core" as core; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self2::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self2::C::test(); + new self2::C::•().{self2::C::test2}(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41498_lib.dart b/pkg/front_end/testcases/nnbd/issue41498_lib.dart new file mode 100644 index 00000000000..9d4a4231a1a --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498_lib.dart @@ -0,0 +1,36 @@ +// 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. + +// @dart=2.6 +library opted_out_lib; + +typedef void LegacyFoo(); + +class C { + static void test() { + LegacyFoo f; + + f.toString(); // ok + } + + void test2() { + LegacyFoo f; + + f.toString(); // ok + } +} + +test() { + LegacyFoo f; + + f.toString(); // ok + + Function foo = () { + LegacyFoo f; + + f.toString(); // ok + }; + C.test(); + new C().test2(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41498b.dart b/pkg/front_end/testcases/nnbd/issue41498b.dart new file mode 100644 index 00000000000..4a6a49cbaa7 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498b.dart @@ -0,0 +1,42 @@ +// 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. + +// @dart=2.6 +library opted_out_lib; + +import 'issue41498b_lib.dart' as opt_in; + +typedef void LegacyFoo(); + +class C { + static void test() { + LegacyFoo f; + + f.toString(); // ok + } + + void test2() { + LegacyFoo f; + + f.toString(); // ok + } +} + +test() { + LegacyFoo f; + + f.toString(); // ok + + Function foo = () { + LegacyFoo f; + + f.toString(); // ok + }; + C.test(); + new C().test2(); +} + +main() { + opt_in.main(); +} diff --git a/pkg/front_end/testcases/nnbd/issue41498b.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue41498b.dart.outline.expect new file mode 100644 index 00000000000..86599c894b6 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498b.dart.outline.expect @@ -0,0 +1,38 @@ +library opted_out_lib; +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self::C* + ; + static method test() → void + ; + method test2() → void + ; +} +static method test() → dynamic + ; +static method main() → dynamic + ; + +library /*isNonNullableByDefault*/; +import self as self2; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498b.dart"; + +class C extends core::Object { + synthetic constructor •() → self2::C + ; + static method test() → void + ; + method test2() → void + ; +} +static method test() → dynamic + ; +static method main() → dynamic + ; diff --git a/pkg/front_end/testcases/nnbd/issue41498b.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue41498b.dart.strong.expect new file mode 100644 index 00000000000..6d86cf58d74 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498b.dart.strong.expect @@ -0,0 +1,92 @@ +library opted_out_lib; +import self as self; +import "dart:core" as core; +import "issue41498b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41498b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498b.dart"; + +class C extends core::Object { + synthetic constructor •() → iss::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + iss::C::test(); + new iss::C::•().{iss::C::test2}(); +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41498b.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue41498b.dart.strong.transformed.expect new file mode 100644 index 00000000000..6d86cf58d74 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498b.dart.strong.transformed.expect @@ -0,0 +1,92 @@ +library opted_out_lib; +import self as self; +import "dart:core" as core; +import "issue41498b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41498b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498b.dart"; + +class C extends core::Object { + synthetic constructor •() → iss::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + iss::C::test(); + new iss::C::•().{iss::C::test2}(); +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41498b.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue41498b.dart.weak.expect new file mode 100644 index 00000000000..6d86cf58d74 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498b.dart.weak.expect @@ -0,0 +1,92 @@ +library opted_out_lib; +import self as self; +import "dart:core" as core; +import "issue41498b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41498b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498b.dart"; + +class C extends core::Object { + synthetic constructor •() → iss::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + iss::C::test(); + new iss::C::•().{iss::C::test2}(); +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41498b.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue41498b.dart.weak.transformed.expect new file mode 100644 index 00000000000..6d86cf58d74 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498b.dart.weak.transformed.expect @@ -0,0 +1,92 @@ +library opted_out_lib; +import self as self; +import "dart:core" as core; +import "issue41498b_lib.dart" as iss; + +import "org-dartlang-testcase:///issue41498b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +class C extends core::Object { + synthetic constructor •() → self::C* + : super core::Object::•() + ; + static method test() → void { + () →* void f; + f.{core::Object::toString}(); + } + method test2() → void { + () →* void f; + f.{core::Object::toString}(); + } +} +static method test() → dynamic { + () →* void f; + f.{core::Object::toString}(); + core::Function* foo = () → core::Null? { + () →* void f; + f.{core::Object::toString}(); + }; + self::C::test(); + new self::C::•().{self::C::test2}(); +} +static method main() → dynamic { + iss::main(); +} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. +// f.toString(); // error +// ^ +// +import self as iss; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41498b.dart"; + +class C extends core::Object { + synthetic constructor •() → iss::C + : super core::Object::•() + ; + static method test() → void { + () → void f; + (let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:11:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } + method test2() → void { + () → void f; + (let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:17:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + } +} +static method test() → dynamic { + () → void f; + (let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:24:3: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + core::Function foo = () → core::Null? { + () → void f; + (let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41498b_lib.dart:29:5: Error: Non-nullable variable 'f' must be assigned before it can be used. + f.toString(); // error + ^" in f).{core::Object::toString}(); + }; + iss::C::test(); + new iss::C::•().{iss::C::test2}(); +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41498b_lib.dart b/pkg/front_end/testcases/nnbd/issue41498b_lib.dart new file mode 100644 index 00000000000..ba3e746fb03 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41498b_lib.dart @@ -0,0 +1,35 @@ +// 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 "issue41498b.dart"; + +class C { + static void test() { + LegacyFoo f; + + f.toString(); // error + } + + void test2() { + LegacyFoo f; + + f.toString(); // error + } +} + +test() { + LegacyFoo f; + + f.toString(); // error + + Function foo = () { + LegacyFoo f; + + f.toString(); // error + }; + C.test(); + new C().test2(); +} + +main() {} diff --git a/pkg/front_end/testcases/nnbd/issue41499.dart b/pkg/front_end/testcases/nnbd/issue41499.dart new file mode 100644 index 00000000000..60fac65834a --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499.dart @@ -0,0 +1,17 @@ +// 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 "issue41499_lib.dart"; + +class C { + static LegacyFoo sTest() {} + + LegacyFoo mTest() {} + + LegacyFoo get gTest {} +} + +LegacyFoo test() {} + +main() {} diff --git a/pkg/front_end/testcases/nnbd/issue41499.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue41499.dart.outline.expect new file mode 100644 index 00000000000..4b8ad7d7831 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499.dart.outline.expect @@ -0,0 +1,27 @@ +library /*isNonNullableByDefault*/; +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + ; + static method sTest() → () → void + ; + method mTest() → () → void + ; + get gTest() → () → void + ; +} +static method test() → () → void + ; +static method main() → dynamic + ; + +library; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic + ; diff --git a/pkg/front_end/testcases/nnbd/issue41499.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue41499.dart.strong.expect new file mode 100644 index 00000000000..e55976c8687 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499.dart.strong.expect @@ -0,0 +1,57 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} +static method main() → dynamic {} + +library; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41499.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue41499.dart.strong.transformed.expect new file mode 100644 index 00000000000..e55976c8687 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499.dart.strong.transformed.expect @@ -0,0 +1,57 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} +static method main() → dynamic {} + +library; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41499.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue41499.dart.weak.expect new file mode 100644 index 00000000000..e55976c8687 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499.dart.weak.expect @@ -0,0 +1,57 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} +static method main() → dynamic {} + +library; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41499.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue41499.dart.weak.transformed.expect new file mode 100644 index 00000000000..e55976c8687 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499.dart.weak.transformed.expect @@ -0,0 +1,57 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499_lib.dart"; + +class C extends core::Object { + synthetic constructor •() → self::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} +static method main() → dynamic {} + +library; +import self as self2; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} diff --git a/pkg/front_end/testcases/nnbd/issue41499_lib.dart b/pkg/front_end/testcases/nnbd/issue41499_lib.dart new file mode 100644 index 00000000000..ae38a197202 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499_lib.dart @@ -0,0 +1,8 @@ +// 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. + +// @dart=2.6 +typedef void LegacyFoo(); + +test(LegacyFoo f) {} diff --git a/pkg/front_end/testcases/nnbd/issue41499b.dart b/pkg/front_end/testcases/nnbd/issue41499b.dart new file mode 100644 index 00000000000..e03840c643c --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499b.dart @@ -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. + +// @dart=2.6 + +import 'issue41499b_lib.dart' as opt_in; + +typedef void LegacyFoo(); + +test(LegacyFoo f) {} + +main() {} diff --git a/pkg/front_end/testcases/nnbd/issue41499b.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue41499b.dart.outline.expect new file mode 100644 index 00000000000..dd70ad63bfa --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499b.dart.outline.expect @@ -0,0 +1,29 @@ +library; +import self as self; + +import "org-dartlang-testcase:///issue41499b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic + ; +static method main() → dynamic + ; + +library /*isNonNullableByDefault*/; +import self as self2; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499b.dart"; + +class C extends core::Object { + synthetic constructor •() → self2::C + ; + static method sTest() → () → void + ; + method mTest() → () → void + ; + get gTest() → () → void + ; +} +static method test() → () → void + ; diff --git a/pkg/front_end/testcases/nnbd/issue41499b.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue41499b.dart.strong.expect new file mode 100644 index 00000000000..06d47155726 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499b.dart.strong.expect @@ -0,0 +1,59 @@ +library; +import self as self; + +import "org-dartlang-testcase:///issue41499b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic {} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self2; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499b.dart"; + +class C extends core::Object { + synthetic constructor •() → self2::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} diff --git a/pkg/front_end/testcases/nnbd/issue41499b.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue41499b.dart.strong.transformed.expect new file mode 100644 index 00000000000..06d47155726 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499b.dart.strong.transformed.expect @@ -0,0 +1,59 @@ +library; +import self as self; + +import "org-dartlang-testcase:///issue41499b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic {} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self2; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499b.dart"; + +class C extends core::Object { + synthetic constructor •() → self2::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} diff --git a/pkg/front_end/testcases/nnbd/issue41499b.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue41499b.dart.weak.expect new file mode 100644 index 00000000000..06d47155726 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499b.dart.weak.expect @@ -0,0 +1,59 @@ +library; +import self as self; + +import "org-dartlang-testcase:///issue41499b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic {} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self2; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499b.dart"; + +class C extends core::Object { + synthetic constructor •() → self2::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} diff --git a/pkg/front_end/testcases/nnbd/issue41499b.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue41499b.dart.weak.transformed.expect new file mode 100644 index 00000000000..06d47155726 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499b.dart.weak.transformed.expect @@ -0,0 +1,59 @@ +library; +import self as self; + +import "org-dartlang-testcase:///issue41499b_lib.dart" as opt_in; + +typedef LegacyFoo = () →* void; +static method test(() →* void f) → dynamic {} +static method main() → dynamic {} + +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// static LegacyFoo sTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo mTest() {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo get gTest {} +// ^ +// +// pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +// LegacyFoo test() {} +// ^ +// +import self as self2; +import "dart:core" as core; + +import "org-dartlang-testcase:///issue41499b.dart"; + +class C extends core::Object { + synthetic constructor •() → self2::C + : super core::Object::•() + ; + static method sTest() → () → void { + return let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:8:20: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + static LegacyFoo sTest() {} + ^" in null; + } + method mTest() → () → void { + return let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:10:13: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo mTest() {} + ^" in null; + } + get gTest() → () → void { + return let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:12:17: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. + LegacyFoo get gTest {} + ^" in null; + } +} +static method test() → () → void { + return let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue41499b_lib.dart:15:11: Error: A non-null value must be returned since the return type 'void Function()' doesn't allow null. +LegacyFoo test() {} + ^" in null; +} diff --git a/pkg/front_end/testcases/nnbd/issue41499b_lib.dart b/pkg/front_end/testcases/nnbd/issue41499b_lib.dart new file mode 100644 index 00000000000..0e205c20545 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue41499b_lib.dart @@ -0,0 +1,15 @@ +// 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 "issue41499b.dart"; + +class C { + static LegacyFoo sTest() {} + + LegacyFoo mTest() {} + + LegacyFoo get gTest {} +} + +LegacyFoo test() {} diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart new file mode 100644 index 00000000000..0b00978941b --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart @@ -0,0 +1,21 @@ +// 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:async'; +import 'issue41501_lib.dart'; + +typedef AAliasNonNullable = A; + +typedef AAliasNullable = A?; + +test() { + FutureOr foLegacyNonNullable = null; // error + FutureOr foLegacyNullable = null; // ok + FutureOr foNonNullable = null; // error + FutureOr foNullable = null; // ok + FutureOr foNonNullableNullable = null; // ok + FutureOr foNullableNullable = null; // ok +} + +main() {} \ No newline at end of file diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.outline.expect b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.outline.expect new file mode 100644 index 00000000000..7f9a2935237 --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.outline.expect @@ -0,0 +1,28 @@ +library /*isNonNullableByDefault*/; +import self as self; +import "issue41501_lib.dart" as opt; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501_lib.dart"; + +typedef AAliasNonNullable = opt::A; +typedef AAliasNullable = opt::A?; +static method test() → dynamic + ; +static method main() → dynamic + ; + +library opted_out_lib; +import self as opt; +import "dart:core" as core; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501.dart"; + +typedef AAlias = opt::A*; +class A extends core::Object { + synthetic constructor •() → opt::A* + ; +} +static method test() → dynamic + ; diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.expect b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.expect new file mode 100644 index 00000000000..6d57a3cf08f --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.expect @@ -0,0 +1,62 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foLegacyNonNullable = null; // error +// ^ +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foNonNullable = null; // error +// ^ +// +import self as self; +import "issue41501_lib.dart" as opt; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501_lib.dart"; + +typedef AAliasNonNullable = opt::A; +typedef AAliasNullable = opt::A?; +static method test() → dynamic { + asy::FutureOr foLegacyNonNullable = let final #t1 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foLegacyNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foLegacyNullable = null; + asy::FutureOr foNonNullable = let final #t2 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foNullable = null; + asy::FutureOr foNonNullableNullable = null; + asy::FutureOr foNullableNullable = null; +} +static method main() → dynamic {} + +library opted_out_lib; +import self as opt; +import "dart:core" as core; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501.dart"; + +typedef AAlias = opt::A*; +class A extends core::Object { + synthetic constructor •() → opt::A* + : super core::Object::•() + ; +} +static method test() → dynamic { + asy::FutureOr* foLegacy = null; + asy::FutureOr* foNonNullable = null; + asy::FutureOr* foNullable = null; +} diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.transformed.expect b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.transformed.expect new file mode 100644 index 00000000000..6d57a3cf08f --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.strong.transformed.expect @@ -0,0 +1,62 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foLegacyNonNullable = null; // error +// ^ +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foNonNullable = null; // error +// ^ +// +import self as self; +import "issue41501_lib.dart" as opt; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501_lib.dart"; + +typedef AAliasNonNullable = opt::A; +typedef AAliasNullable = opt::A?; +static method test() → dynamic { + asy::FutureOr foLegacyNonNullable = let final #t1 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foLegacyNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foLegacyNullable = null; + asy::FutureOr foNonNullable = let final #t2 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foNullable = null; + asy::FutureOr foNonNullableNullable = null; + asy::FutureOr foNullableNullable = null; +} +static method main() → dynamic {} + +library opted_out_lib; +import self as opt; +import "dart:core" as core; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501.dart"; + +typedef AAlias = opt::A*; +class A extends core::Object { + synthetic constructor •() → opt::A* + : super core::Object::•() + ; +} +static method test() → dynamic { + asy::FutureOr* foLegacy = null; + asy::FutureOr* foNonNullable = null; + asy::FutureOr* foNullable = null; +} diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.expect b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.expect new file mode 100644 index 00000000000..6d57a3cf08f --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.expect @@ -0,0 +1,62 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foLegacyNonNullable = null; // error +// ^ +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foNonNullable = null; // error +// ^ +// +import self as self; +import "issue41501_lib.dart" as opt; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501_lib.dart"; + +typedef AAliasNonNullable = opt::A; +typedef AAliasNullable = opt::A?; +static method test() → dynamic { + asy::FutureOr foLegacyNonNullable = let final #t1 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foLegacyNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foLegacyNullable = null; + asy::FutureOr foNonNullable = let final #t2 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foNullable = null; + asy::FutureOr foNonNullableNullable = null; + asy::FutureOr foNullableNullable = null; +} +static method main() → dynamic {} + +library opted_out_lib; +import self as opt; +import "dart:core" as core; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501.dart"; + +typedef AAlias = opt::A*; +class A extends core::Object { + synthetic constructor •() → opt::A* + : super core::Object::•() + ; +} +static method test() → dynamic { + asy::FutureOr* foLegacy = null; + asy::FutureOr* foNonNullable = null; + asy::FutureOr* foNullable = null; +} diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.transformed.expect b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.transformed.expect new file mode 100644 index 00000000000..6d57a3cf08f --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart.weak.transformed.expect @@ -0,0 +1,62 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foLegacyNonNullable = null; // error +// ^ +// +// pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. +// - 'FutureOr' is from 'dart:async'. +// - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. +// FutureOr foNonNullable = null; // error +// ^ +// +import self as self; +import "issue41501_lib.dart" as opt; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501_lib.dart"; + +typedef AAliasNonNullable = opt::A; +typedef AAliasNullable = opt::A?; +static method test() → dynamic { + asy::FutureOr foLegacyNonNullable = let final #t1 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:13:42: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foLegacyNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foLegacyNullable = null; + asy::FutureOr foNonNullable = let final #t2 = invalid-expression "pkg/front_end/testcases/nonfunction_type_aliases/issue41501.dart:15:47: Error: A value of type 'Null?' can't be assigned to a variable of type 'FutureOr'. + - 'FutureOr' is from 'dart:async'. + - 'A' is from 'pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart'. + FutureOr foNonNullable = null; // error + ^" in null as{TypeError,ForNonNullableByDefault} asy::FutureOr; + asy::FutureOr foNullable = null; + asy::FutureOr foNonNullableNullable = null; + asy::FutureOr foNullableNullable = null; +} +static method main() → dynamic {} + +library opted_out_lib; +import self as opt; +import "dart:core" as core; +import "dart:async" as asy; + +import "dart:async"; +import "org-dartlang-testcase:///issue41501.dart"; + +typedef AAlias = opt::A*; +class A extends core::Object { + synthetic constructor •() → opt::A* + : super core::Object::•() + ; +} +static method test() → dynamic { + asy::FutureOr* foLegacy = null; + asy::FutureOr* foNonNullable = null; + asy::FutureOr* foNullable = null; +} diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart new file mode 100644 index 00000000000..09e20d1d119 --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/issue41501_lib.dart @@ -0,0 +1,21 @@ +// 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. + +// @dart=2.6 + +library opted_out_lib; + +import 'dart:async'; +import 'issue41501.dart'; + +class A {} + +typedef AAlias = A; + +test() { + FutureOr foLegacy = null; // ok + FutureOr foNonNullable = null; // ok + FutureOr foNullable = null; // ok +} + diff --git a/pkg/front_end/testcases/nonfunction_type_aliases/test.options b/pkg/front_end/testcases/nonfunction_type_aliases/test.options new file mode 100644 index 00000000000..e7c1048e031 --- /dev/null +++ b/pkg/front_end/testcases/nonfunction_type_aliases/test.options @@ -0,0 +1 @@ +--enable-experiment=non-nullable,nonfunction-type-aliases \ No newline at end of file diff --git a/pkg/front_end/testcases/text_serialization.status b/pkg/front_end/testcases/text_serialization.status index 69a3a5d2bce..64d249ddde5 100644 --- a/pkg/front_end/testcases/text_serialization.status +++ b/pkg/front_end/testcases/text_serialization.status @@ -1310,6 +1310,12 @@ nnbd/issue41180: TextSerializationFailure nnbd/issue41210a/issue41210: TextSerializationFailure nnbd/issue41210b: TextSerializationFailure nnbd/issue41273: TextSerializationFailure +nnbd/issue41496: TextSerializationFailure +nnbd/issue41496b: TextSerializationFailure +nnbd/issue41498: TextSerializationFailure +nnbd/issue41498b: TextSerializationFailure +nnbd/issue41499: TextSerializationFailure +nnbd/issue41499b: TextSerializationFailure nnbd/issue_39286: TextSerializationFailure nnbd/issue_39286_2: TextSerializationFailure nnbd/late: TextSerializationFailure @@ -1403,6 +1409,7 @@ no_such_method_forwarders/private_same: TextSerializationFailure # Was: Pass no_such_method_forwarders/same: TextSerializationFailure # Was: Pass no_such_method_forwarders/setter_not_shadowed_by_method: TextSerializationFailure # Was: Pass no_such_method_forwarders/subst_on_forwarder: TextSerializationFailure # Was: Pass +nonfunction_type_aliases/issue41501: TextSerializationFailure rasta/abstract_constructor: TextSerializationFailure # Was: RuntimeError rasta/bad_constructor_redirection: TextSerializationFailure # Was: RuntimeError rasta/bad_continue: TextSerializationFailure # Was: RuntimeError diff --git a/tools/generate_package_config.dart b/tools/generate_package_config.dart index 3d415c3f770..19e9c94b035 100755 --- a/tools/generate_package_config.dart +++ b/tools/generate_package_config.dart @@ -34,6 +34,7 @@ void main(List args) { packageDirectory('pkg/front_end/testcases/general_nnbd_opt_out/'), packageDirectory('pkg/front_end/testcases/late_lowering/'), packageDirectory('pkg/front_end/testcases/nnbd/'), + packageDirectory('pkg/front_end/testcases/nonfunction_type_aliases/'), ]; var packages = [