diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart index 0755e0d715f..da02e67a268 100644 --- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart @@ -326,12 +326,12 @@ class KernelTarget extends TargetImplementation { loader.computeHierarchy(); loader.performTopLevelInference(myClasses); loader.checkSupertypes(myClasses); - loader.checkTypes(); loader.checkOverrides(myClasses); loader.checkAbstractMembers(myClasses); loader.addNoSuchMethodForwarders(myClasses); loader.checkMixins(myClasses); loader.buildOutlineExpressions(loader.coreTypes); + loader.checkTypes(); loader.checkRedirectingFactories(myClasses); _updateDelayedParameterTypes(); installAllComponentProblems(loader.allComponentProblems); diff --git a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart index dd4152e4dbf..c1cbe7d4a8a 100644 --- a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart @@ -16,6 +16,7 @@ import 'package:kernel/type_environment.dart'; import '../builder/builder.dart'; import '../builder/class_builder.dart'; +import '../builder/constructor_builder.dart'; import '../builder/constructor_reference_builder.dart'; import '../builder/field_builder.dart'; import '../builder/function_builder.dart'; @@ -582,7 +583,16 @@ class SourceClassBuilder extends ClassBuilderImpl // Check initializers. if (builder is FunctionBuilder && - !builder.isAbstract && + !(builder.isAbstract || builder.isExternal) && + builder.formals != null) { + libraryBuilder.checkInitializersInFormals( + builder.formals, typeEnvironment); + } + }); + + constructors.local.forEach((String name, MemberBuilder builder) { + if (builder is ConstructorBuilder && + !builder.isExternal && builder.formals != null) { libraryBuilder.checkInitializersInFormals( builder.formals, typeEnvironment); diff --git a/pkg/front_end/test/patching/data/const_constructors/patch.dart b/pkg/front_end/test/patching/data/const_constructors/patch.dart index c2396919303..1b92dab46cb 100644 --- a/pkg/front_end/test/patching/data/const_constructors/patch.dart +++ b/pkg/front_end/test/patching/data/const_constructors/patch.dart @@ -16,5 +16,5 @@ class PatchedClass { patch */ @patch - const PatchedClass({int field}) : _field = field; + const PatchedClass({int field: 0}) : _field = field; } diff --git a/pkg/front_end/testcases/nnbd/issue42143.dart b/pkg/front_end/testcases/nnbd/issue42143.dart index a711b13e8cc..03266d7e7e6 100644 --- a/pkg/front_end/testcases/nnbd/issue42143.dart +++ b/pkg/front_end/testcases/nnbd/issue42143.dart @@ -1,3 +1,7 @@ +// 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'; void h1?>(T? t) {} diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart b/pkg/front_end/testcases/nnbd/issue42362.dart new file mode 100644 index 00000000000..fe7cc97b615 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart @@ -0,0 +1,109 @@ +// 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. + +class A { + final int i; + + A.constructor1([this.i]); // error + + A.constructor2({this.i}); // error + + A.constructor3([int i]) // error + : this.i = i; // ok + + A.constructor4({int i}) // error + : this.i = i; // ok + + A.constructor5([int? i]) // ok + : this.i = i; // error + + A.constructor6({int? i}) // ok + : this.i = i; // error + + A.constructor7({required int i}) // ok + : this.i = i; // ok + + external A.constructor8([int i]); // ok + + external A.constructor9({int i}); // ok + + factory A.factory3([int i]) = A.constructor3; // ok + + factory A.factory4({int i}) = A.constructor4; // ok + + factory A.factory5([int? i]) = A.constructor5; // ok + + factory A.factory6({int? i}) = A.constructor6; // ok + + factory A.factory7({required int i}) = A.constructor7; // ok + + method3([int i]) {} // error + + method4({int i}) {} // error + + method5([int? i]) {} // ok + + method6({int? i}) {} // ok + + method7({required int i}) {} // ok + + external method8([int i]); // ok + + external method9({int i}); // ok +} + +abstract class B { + var i = 42; + + method3([int i]); // ok + + method4({int i}); // ok + + method5([int? i]); // ok + + method6({int? i}); // ok + + method7({required int i}); // ok +} + +class C implements B { + var i; + + C.constructor1([this.i]); // error + + C.constructor2({this.i}); // error + + C.constructor3([int i]) : this.i = i; // error + + C.constructor4({int i}) : this.i = i; // error + + C.constructor5([int? i]) : this.i = i; // error + + C.constructor6({int? i}) : this.i = i; // error + + C.constructor7({required int i}) // ok + : this.i = i; // ok + + factory C.factory3([int i]) = C.constructor3; // ok + + factory C.factory4({int i}) = C.constructor4; // ok + + factory C.factory5([int? i]) = C.constructor5; // ok + + factory C.factory6({int? i}) = C.constructor6; // ok + + factory C.factory7({required int i}) = C.constructor7; // ok + + method3([i]) {} // error + + method4({i}) {} // error + + method5([i]) {} // ok + + method6({i}) {} // ok + + method7({required i}) {} // ok +} + +void main() {} diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue42362.dart.outline.expect new file mode 100644 index 00000000000..2911d31ea63 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart.outline.expect @@ -0,0 +1,149 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue42362.dart:41:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([int i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:43:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({int i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:8:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:10:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:12:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor3([int i]) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:15:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor4({int i}) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:98:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:100:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:73:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:75:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:77:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor3([int i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:79:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor4({int i}) : this.i = i; // error +// ^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int i; + static field dynamic _redirecting# = [self::A::factory3, self::A::factory4, self::A::factory5, self::A::factory6, self::A::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i]) → self::A + ; + constructor constructor2({core::int i}) → self::A + ; + constructor constructor3([core::int i]) → self::A + ; + constructor constructor4({core::int i}) → self::A + ; + constructor constructor5([core::int? i]) → self::A + ; + constructor constructor6({core::int? i}) → self::A + ; + constructor constructor7({required core::int i}) → self::A + ; + external constructor constructor8([core::int i]) → self::A + ; + external constructor constructor9({core::int i}) → self::A + ; + static factory factory3([core::int i]) → self::A + let dynamic #redirecting_factory = self::A::constructor3 in invalid-expression; + static factory factory4({core::int i}) → self::A + let dynamic #redirecting_factory = self::A::constructor4 in invalid-expression; + static factory factory5([core::int? i]) → self::A + let dynamic #redirecting_factory = self::A::constructor5 in invalid-expression; + static factory factory6({core::int? i}) → self::A + let dynamic #redirecting_factory = self::A::constructor6 in invalid-expression; + static factory factory7({required core::int i}) → self::A + let dynamic #redirecting_factory = self::A::constructor7 in invalid-expression; + method method3([core::int i]) → dynamic + ; + method method4({core::int i}) → dynamic + ; + method method5([core::int? i]) → dynamic + ; + method method6({core::int? i}) → dynamic + ; + method method7({required core::int i}) → dynamic + ; + external method method8([core::int i]) → dynamic; + external method method9({core::int i}) → dynamic; +} +abstract class B extends core::Object { + field core::int i; + synthetic constructor •() → self::B + ; + abstract method method3([core::int i]) → dynamic; + abstract method method4({core::int i}) → dynamic; + abstract method method5([core::int? i]) → dynamic; + abstract method method6({core::int? i}) → dynamic; + abstract method method7({required core::int i}) → dynamic; +} +class C extends core::Object implements self::B { + field core::int i; + static field dynamic _redirecting# = [self::C::factory3, self::C::factory4, self::C::factory5, self::C::factory6, self::C::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i]) → self::C + ; + constructor constructor2({core::int i}) → self::C + ; + constructor constructor3([core::int i]) → self::C + ; + constructor constructor4({core::int i}) → self::C + ; + constructor constructor5([core::int? i]) → self::C + ; + constructor constructor6({core::int? i}) → self::C + ; + constructor constructor7({required core::int i}) → self::C + ; + static factory factory3([core::int i]) → self::C + let dynamic #redirecting_factory = self::C::constructor3 in invalid-expression; + static factory factory4({core::int i}) → self::C + let dynamic #redirecting_factory = self::C::constructor4 in invalid-expression; + static factory factory5([core::int? i]) → self::C + let dynamic #redirecting_factory = self::C::constructor5 in invalid-expression; + static factory factory6({core::int? i}) → self::C + let dynamic #redirecting_factory = self::C::constructor6 in invalid-expression; + static factory factory7({required core::int i}) → self::C + let dynamic #redirecting_factory = self::C::constructor7 in invalid-expression; + method method3([core::int i]) → dynamic + ; + method method4({core::int i}) → dynamic + ; + method method5([core::int? i]) → dynamic + ; + method method6({core::int? i}) → dynamic + ; + method method7({required core::int i}) → dynamic + ; +} +static method main() → void + ; diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue42362.dart.strong.expect new file mode 100644 index 00000000000..7579211ef38 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart.strong.expect @@ -0,0 +1,183 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue42362.dart:41:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([int i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:43:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({int i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:8:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:10:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:12:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor3([int i]) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:15:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor4({int i}) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:98:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:100:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:73:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:75:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:77:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor3([int i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:79:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor4({int i}) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor5([int? i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor6({int? i}) : this.i = i; // error +// ^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int i; + static field dynamic _redirecting# = [self::A::factory3, self::A::factory4, self::A::factory5, self::A::factory6, self::A::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::A + : self::A::i = let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::A + : self::A::i = let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + external constructor constructor8([core::int i = #C1]) → self::A + : super core::Object::•() + ; + external constructor constructor9({core::int i = #C1}) → self::A + : super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::A + let dynamic #redirecting_factory = self::A::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::A + let dynamic #redirecting_factory = self::A::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::A + let dynamic #redirecting_factory = self::A::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::A + let dynamic #redirecting_factory = self::A::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::A + let dynamic #redirecting_factory = self::A::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} + external method method8([core::int i = #C1]) → dynamic; + external method method9({core::int i = #C1}) → dynamic; +} +abstract class B extends core::Object { + field core::int i = 42; + synthetic constructor •() → self::B + : super core::Object::•() + ; + abstract method method3([core::int i = #C1]) → dynamic; + abstract method method4({core::int i = #C1}) → dynamic; + abstract method method5([core::int? i = #C1]) → dynamic; + abstract method method6({core::int? i = #C1}) → dynamic; + abstract method method7({required core::int i = #C1}) → dynamic; +} +class C extends core::Object implements self::B { + field core::int i; + static field dynamic _redirecting# = [self::C::factory3, self::C::factory4, self::C::factory5, self::C::factory6, self::C::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::C + : self::C::i = let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor5([int? i]) : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::C + : self::C::i = let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor6({int? i}) : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::C + let dynamic #redirecting_factory = self::C::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::C + let dynamic #redirecting_factory = self::C::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::C + let dynamic #redirecting_factory = self::C::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::C + let dynamic #redirecting_factory = self::C::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::C + let dynamic #redirecting_factory = self::C::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} +} +static method main() → void {} + +constants { + #C1 = null +} diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue42362.dart.strong.transformed.expect new file mode 100644 index 00000000000..c847fd5935e --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart.strong.transformed.expect @@ -0,0 +1,183 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue42362.dart:41:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([int i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:43:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({int i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:8:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:10:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:12:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor3([int i]) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:15:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor4({int i}) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:98:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:100:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:73:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:75:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:77:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor3([int i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:79:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor4({int i}) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor5([int? i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor6({int? i}) : this.i = i; // error +// ^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int i; + static field dynamic _redirecting# = [self::A::factory3, self::A::factory4, self::A::factory5, self::A::factory6, self::A::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::A + : self::A::i = let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in let core::int? #t2 = i in #t2.==(null) ?{core::int} #t2 as{TypeError,ForNonNullableByDefault} core::int : #t2{core::int}, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::A + : self::A::i = let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in let core::int? #t4 = i in #t4.==(null) ?{core::int} #t4 as{TypeError,ForNonNullableByDefault} core::int : #t4{core::int}, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + external constructor constructor8([core::int i = #C1]) → self::A + : super core::Object::•() + ; + external constructor constructor9({core::int i = #C1}) → self::A + : super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::A + let #redirecting_factory = self::A::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::A + let #redirecting_factory = self::A::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::A + let #redirecting_factory = self::A::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::A + let #redirecting_factory = self::A::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::A + let #redirecting_factory = self::A::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} + external method method8([core::int i = #C1]) → dynamic; + external method method9({core::int i = #C1}) → dynamic; +} +abstract class B extends core::Object { + field core::int i = 42; + synthetic constructor •() → self::B + : super core::Object::•() + ; + abstract method method3([core::int i = #C1]) → dynamic; + abstract method method4({core::int i = #C1}) → dynamic; + abstract method method5([core::int? i = #C1]) → dynamic; + abstract method method6({core::int? i = #C1}) → dynamic; + abstract method method7({required core::int i = #C1}) → dynamic; +} +class C extends core::Object implements self::B { + field core::int i; + static field dynamic _redirecting# = [self::C::factory3, self::C::factory4, self::C::factory5, self::C::factory6, self::C::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::C + : self::C::i = let final #t5 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor5([int? i]) : this.i = i; // error + ^" in let core::int? #t6 = i in #t6.==(null) ?{core::int} #t6 as{TypeError,ForNonNullableByDefault} core::int : #t6{core::int}, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::C + : self::C::i = let final #t7 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor6({int? i}) : this.i = i; // error + ^" in let core::int? #t8 = i in #t8.==(null) ?{core::int} #t8 as{TypeError,ForNonNullableByDefault} core::int : #t8{core::int}, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::C + let #redirecting_factory = self::C::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::C + let #redirecting_factory = self::C::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::C + let #redirecting_factory = self::C::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::C + let #redirecting_factory = self::C::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::C + let #redirecting_factory = self::C::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} +} +static method main() → void {} + +constants { + #C1 = null +} diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart.textual_outline.expect b/pkg/front_end/testcases/nnbd/issue42362.dart.textual_outline.expect new file mode 100644 index 00000000000..7110b99e6af --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart.textual_outline.expect @@ -0,0 +1,56 @@ +class A { + final int i; + A.constructor1([this.i]); + A.constructor2({this.i}); + A.constructor3([int i]) : this.i = i; + A.constructor4({int i}) : this.i = i; + A.constructor5([int? i]) : this.i = i; + A.constructor6({int? i}) : this.i = i; + A.constructor7({required int i}) : this.i = i; + external A.constructor8([int i]); + external A.constructor9({int i}); + factory A.factory3([int i]) = A.constructor3; + factory A.factory4({int i}) = A.constructor4; + factory A.factory5([int? i]) = A.constructor5; + factory A.factory6({int? i}) = A.constructor6; + factory A.factory7({required int i}) = A.constructor7; + method3([int i]) {} + method4({int i}) {} + method5([int? i]) {} + method6({int? i}) {} + method7({required int i}) {} + external method8([int i]); + external method9({int i}); +} + +abstract class B { + var i = 42; + method3([int i]); + method4({int i}); + method5([int? i]); + method6({int? i}); + method7({required int i}); +} + +class C implements B { + var i; + C.constructor1([this.i]); + C.constructor2({this.i}); + C.constructor3([int i]) : this.i = i; + C.constructor4({int i}) : this.i = i; + C.constructor5([int? i]) : this.i = i; + C.constructor6({int? i}) : this.i = i; + C.constructor7({required int i}) : this.i = i; + factory C.factory3([int i]) = C.constructor3; + factory C.factory4({int i}) = C.constructor4; + factory C.factory5([int? i]) = C.constructor5; + factory C.factory6({int? i}) = C.constructor6; + factory C.factory7({required int i}) = C.constructor7; + method3([i]) {} + method4({i}) {} + method5([i]) {} + method6({i}) {} + method7({required i}) {} +} + +void main() {} diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/nnbd/issue42362.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..294d4f9ac6a --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart.textual_outline_modelled.expect @@ -0,0 +1,56 @@ +abstract class B { + method3([int i]); + method4({int i}); + method5([int? i]); + method6({int? i}); + method7({required int i}); + var i = 42; +} + +class A { + A.constructor1([this.i]); + A.constructor2({this.i}); + A.constructor3([int i]) : this.i = i; + A.constructor4({int i}) : this.i = i; + A.constructor5([int? i]) : this.i = i; + A.constructor6({int? i}) : this.i = i; + A.constructor7({required int i}) : this.i = i; + external A.constructor8([int i]); + external A.constructor9({int i}); + external method8([int i]); + external method9({int i}); + factory A.factory3([int i]) = A.constructor3; + factory A.factory4({int i}) = A.constructor4; + factory A.factory5([int? i]) = A.constructor5; + factory A.factory6({int? i}) = A.constructor6; + factory A.factory7({required int i}) = A.constructor7; + final int i; + method3([int i]) {} + method4({int i}) {} + method5([int? i]) {} + method6({int? i}) {} + method7({required int i}) {} +} + +class C implements B { + C.constructor1([this.i]); + C.constructor2({this.i}); + C.constructor3([int i]) : this.i = i; + C.constructor4({int i}) : this.i = i; + C.constructor5([int? i]) : this.i = i; + C.constructor6({int? i}) : this.i = i; + C.constructor7({required int i}) : this.i = i; + factory C.factory3([int i]) = C.constructor3; + factory C.factory4({int i}) = C.constructor4; + factory C.factory5([int? i]) = C.constructor5; + factory C.factory6({int? i}) = C.constructor6; + factory C.factory7({required int i}) = C.constructor7; + method3([i]) {} + method4({i}) {} + method5([i]) {} + method6({i}) {} + method7({required i}) {} + var i; +} + +void main() {} diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue42362.dart.weak.expect new file mode 100644 index 00000000000..7579211ef38 --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart.weak.expect @@ -0,0 +1,183 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue42362.dart:41:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([int i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:43:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({int i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:8:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:10:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:12:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor3([int i]) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:15:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor4({int i}) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:98:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:100:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:73:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:75:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:77:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor3([int i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:79:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor4({int i}) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor5([int? i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor6({int? i}) : this.i = i; // error +// ^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int i; + static field dynamic _redirecting# = [self::A::factory3, self::A::factory4, self::A::factory5, self::A::factory6, self::A::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::A + : self::A::i = let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::A + : self::A::i = let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + external constructor constructor8([core::int i = #C1]) → self::A + : super core::Object::•() + ; + external constructor constructor9({core::int i = #C1}) → self::A + : super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::A + let dynamic #redirecting_factory = self::A::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::A + let dynamic #redirecting_factory = self::A::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::A + let dynamic #redirecting_factory = self::A::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::A + let dynamic #redirecting_factory = self::A::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::A + let dynamic #redirecting_factory = self::A::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} + external method method8([core::int i = #C1]) → dynamic; + external method method9({core::int i = #C1}) → dynamic; +} +abstract class B extends core::Object { + field core::int i = 42; + synthetic constructor •() → self::B + : super core::Object::•() + ; + abstract method method3([core::int i = #C1]) → dynamic; + abstract method method4({core::int i = #C1}) → dynamic; + abstract method method5([core::int? i = #C1]) → dynamic; + abstract method method6({core::int? i = #C1}) → dynamic; + abstract method method7({required core::int i = #C1}) → dynamic; +} +class C extends core::Object implements self::B { + field core::int i; + static field dynamic _redirecting# = [self::C::factory3, self::C::factory4, self::C::factory5, self::C::factory6, self::C::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::C + : self::C::i = let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor5([int? i]) : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::C + : self::C::i = let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor6({int? i}) : this.i = i; // error + ^" in i as{TypeError,ForNonNullableByDefault} core::int, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::C + let dynamic #redirecting_factory = self::C::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::C + let dynamic #redirecting_factory = self::C::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::C + let dynamic #redirecting_factory = self::C::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::C + let dynamic #redirecting_factory = self::C::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::C + let dynamic #redirecting_factory = self::C::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} +} +static method main() → void {} + +constants { + #C1 = null +} diff --git a/pkg/front_end/testcases/nnbd/issue42362.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue42362.dart.weak.transformed.expect new file mode 100644 index 00000000000..d5a08918c7d --- /dev/null +++ b/pkg/front_end/testcases/nnbd/issue42362.dart.weak.transformed.expect @@ -0,0 +1,183 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/nnbd/issue42362.dart:41:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([int i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:43:16: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({int i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:8:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:10:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:12:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor3([int i]) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:15:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// A.constructor4({int i}) // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:98:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method3([i]) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:100:12: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// method4({i}) {} // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:73:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor1([this.i]); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:75:24: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor2({this.i}); // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:77:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor3([int i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:79:23: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. +// C.constructor4({int i}) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor5([int? i]) : this.i = i; // error +// ^ +// +// pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. +// C.constructor6({int? i}) : this.i = i; // error +// ^ +// +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int i; + static field dynamic _redirecting# = [self::A::factory3, self::A::factory4, self::A::factory5, self::A::factory6, self::A::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::A + : self::A::i = let final #t1 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:19:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in i, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::A + : self::A::i = let final #t2 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:22:18: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + : this.i = i; // error + ^" in i, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::A + : self::A::i = i, super core::Object::•() + ; + external constructor constructor8([core::int i = #C1]) → self::A + : super core::Object::•() + ; + external constructor constructor9({core::int i = #C1}) → self::A + : super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::A + let #redirecting_factory = self::A::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::A + let #redirecting_factory = self::A::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::A + let #redirecting_factory = self::A::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::A + let #redirecting_factory = self::A::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::A + let #redirecting_factory = self::A::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} + external method method8([core::int i = #C1]) → dynamic; + external method method9({core::int i = #C1}) → dynamic; +} +abstract class B extends core::Object { + field core::int i = 42; + synthetic constructor •() → self::B + : super core::Object::•() + ; + abstract method method3([core::int i = #C1]) → dynamic; + abstract method method4({core::int i = #C1}) → dynamic; + abstract method method5([core::int? i = #C1]) → dynamic; + abstract method method6({core::int? i = #C1}) → dynamic; + abstract method method7({required core::int i = #C1}) → dynamic; +} +class C extends core::Object implements self::B { + field core::int i; + static field dynamic _redirecting# = [self::C::factory3, self::C::factory4, self::C::factory5, self::C::factory6, self::C::factory7]/*isNullableByDefault*/; + constructor constructor1([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor2({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor3([core::int i = #C1]) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor4({core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + constructor constructor5([core::int? i = #C1]) → self::C + : self::C::i = let final #t3 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:81:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor5([int? i]) : this.i = i; // error + ^" in i, super core::Object::•() + ; + constructor constructor6({core::int? i = #C1}) → self::C + : self::C::i = let final #t4 = invalid-expression "pkg/front_end/testcases/nnbd/issue42362.dart:83:39: Error: A value of type 'int?' can't be assigned to a variable of type 'int'. + C.constructor6({int? i}) : this.i = i; // error + ^" in i, super core::Object::•() + ; + constructor constructor7({required core::int i = #C1}) → self::C + : self::C::i = i, super core::Object::•() + ; + static factory factory3([core::int i = #C1]) → self::C + let #redirecting_factory = self::C::constructor3 in invalid-expression; + static factory factory4({core::int i = #C1}) → self::C + let #redirecting_factory = self::C::constructor4 in invalid-expression; + static factory factory5([core::int? i = #C1]) → self::C + let #redirecting_factory = self::C::constructor5 in invalid-expression; + static factory factory6({core::int? i = #C1}) → self::C + let #redirecting_factory = self::C::constructor6 in invalid-expression; + static factory factory7({required core::int i = #C1}) → self::C + let #redirecting_factory = self::C::constructor7 in invalid-expression; + method method3([core::int i = #C1]) → dynamic {} + method method4({core::int i = #C1}) → dynamic {} + method method5([core::int? i = #C1]) → dynamic {} + method method6({core::int? i = #C1}) → dynamic {} + method method7({required core::int i = #C1}) → dynamic {} +} +static method main() → void {} + +constants { + #C1 = null +} diff --git a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.outline.expect b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.outline.expect index cae508d4fa3..25d8360107c 100644 --- a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.outline.expect +++ b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.outline.expect @@ -30,10 +30,6 @@ library /*isNonNullableByDefault*/; // void method([int i]) {} // ^ // -// pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:8:36: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. -// external void patchedMethod([int i]); -// ^ -// // pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:11:18: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. // void method([int i]) {} // ^ diff --git a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.expect b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.expect index 9a4131e7558..0c2e5964617 100644 --- a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.expect +++ b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.expect @@ -32,10 +32,6 @@ library /*isNonNullableByDefault*/; // void method([int i]) {} // ^ // -// pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:8:36: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. -// external void patchedMethod([int i]); -// ^ -// // pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:11:18: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. // void method([int i]) {} // ^ diff --git a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.transformed.expect index 9a4131e7558..0c2e5964617 100644 --- a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.strong.transformed.expect @@ -32,10 +32,6 @@ library /*isNonNullableByDefault*/; // void method([int i]) {} // ^ // -// pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:8:36: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. -// external void patchedMethod([int i]); -// ^ -// // pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:11:18: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. // void method([int i]) {} // ^ diff --git a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.expect b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.expect index 9a4131e7558..0c2e5964617 100644 --- a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.expect +++ b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.expect @@ -32,10 +32,6 @@ library /*isNonNullableByDefault*/; // void method([int i]) {} // ^ // -// pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:8:36: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. -// external void patchedMethod([int i]); -// ^ -// // pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:11:18: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. // void method([int i]) {} // ^ diff --git a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.transformed.expect index 9a4131e7558..0c2e5964617 100644 --- a/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/nnbd/platform_optional_parameters/main.dart.weak.transformed.expect @@ -32,10 +32,6 @@ library /*isNonNullableByDefault*/; // void method([int i]) {} // ^ // -// pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:8:36: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. -// external void patchedMethod([int i]); -// ^ -// // pkg/front_end/testcases/nnbd/platform_optional_parameters/origin_lib.dart:11:18: Error: Optional parameter 'i' should have a default value because its type 'int' doesn't allow null. // void method([int i]) {} // ^ diff --git a/runtime/tests/vm/dart/regress_flutter_57398_test.dart b/runtime/tests/vm/dart/regress_flutter_57398_test.dart index a2a93abb78d..c98d96c900b 100644 --- a/runtime/tests/vm/dart/regress_flutter_57398_test.dart +++ b/runtime/tests/vm/dart/regress_flutter_57398_test.dart @@ -9,7 +9,7 @@ import 'dart:async'; import 'package:expect/expect.dart'; class W { - final FutureOr v; + final FutureOr? v; W({this.v}); @pragma('vm:never-inline') diff --git a/sdk/lib/js/_js_annotations.dart b/sdk/lib/js/_js_annotations.dart index 8c8148d01c6..b28e7b75929 100644 --- a/sdk/lib/js/_js_annotations.dart +++ b/sdk/lib/js/_js_annotations.dart @@ -8,7 +8,7 @@ library _js_annotations; class JS { - final String name; + final String? name; const JS([this.name]); } diff --git a/tests/dart2js/async_stacktrace_test.dart b/tests/dart2js/async_stacktrace_test.dart index 708706b96ed..fffb9466d1d 100644 --- a/tests/dart2js/async_stacktrace_test.dart +++ b/tests/dart2js/async_stacktrace_test.dart @@ -9,7 +9,7 @@ import "package:async_helper/async_helper.dart"; class Tracer { final String expected; - final String name; + final String? name; String _trace = ""; Tracer(this.expected, [this.name]); diff --git a/tests/dart2js/recursive_metadata_test.dart b/tests/dart2js/recursive_metadata_test.dart index 1c46209626d..c857bc358a2 100644 --- a/tests/dart2js/recursive_metadata_test.dart +++ b/tests/dart2js/recursive_metadata_test.dart @@ -8,7 +8,7 @@ import 'package:expect/expect.dart'; // to other annotated types. class Annotation { - final String value; + final String? value; const Annotation({this.value}); } @@ -18,9 +18,9 @@ enum Enum { } class SubAnno extends Annotation { - final Enum e; - final Type type; - const SubAnno({String value, this.e, this.type}) : super(value: value); + final Enum? e; + final Type? type; + const SubAnno({String? value, this.e, this.type}) : super(value: value); } @SubAnno(value: 'super')