38d7c7661d
In error reporting on assignability where the expression has type `Null` we use a special messages that doesn't state that "'Null' is nullable". Cases where `Null` is part of the type or where the expression of type `Null` is derived from a collection are not special cased. Closes #43998 Closes #44093 Change-Id: Ic0c79e6362f2365eb3fe8222ccd2ef8fac4f188d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170433 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
85 lines
1.7 KiB
Dart
85 lines
1.7 KiB
Dart
// 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.
|
|
|
|
// The test checks that if one type isn't assignable to the other only because
|
|
// of the nullability modifiers, the error message reflects that.
|
|
|
|
import 'dart:async';
|
|
|
|
class A {
|
|
const A();
|
|
}
|
|
|
|
class B extends A {}
|
|
|
|
class C {
|
|
num? call() {}
|
|
}
|
|
|
|
void fooContext(A x) {}
|
|
|
|
void barContext(List<A> x) {}
|
|
|
|
void bazContext(num Function() f) {}
|
|
|
|
A foo(B? x, List<B?> l, Map<B?, B?> m, List<B>? l2, Map<B, B>? m2) {
|
|
fooContext(x); // Error.
|
|
A a = x; // Error.
|
|
<A>[...l]; // Error.
|
|
<A>[...l2]; // Error.
|
|
<A, A>{...m}; // Error.
|
|
<A, A>{...m2}; // Error.
|
|
for (A y in l) {} // Error.
|
|
for (A y in l2) {} // Error.
|
|
switch (x) /* Error. */ {
|
|
case const A():
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
FutureOr<A> local() async {
|
|
if (true) {
|
|
return x; // Error.
|
|
} else {
|
|
return new Future<B?>.value(x); // Error.
|
|
}
|
|
}
|
|
|
|
return x; // Error.
|
|
}
|
|
|
|
List<A> bar(List<B?> x, List<List<B?>> l, Map<List<B?>, List<B?>> m) {
|
|
barContext(x); // Error.
|
|
List<A> y = x; // Error.
|
|
<List<A>>[...l]; // Error.
|
|
<List<A>, List<A>>{...m}; // Error.
|
|
for (List<A> y in l) {} // Error.
|
|
return x; // Error.
|
|
}
|
|
|
|
void baz(C c) {
|
|
bazContext(c);
|
|
}
|
|
|
|
A boz(Null x) {
|
|
fooContext(x); // Error.
|
|
fooContext(null); // Error.
|
|
A a1 = x; // Error.
|
|
A a2 = null; // Error.
|
|
if (true) {
|
|
return x; // Error.
|
|
} else {
|
|
return null; // Error.
|
|
}
|
|
FutureOr<A> local() async {
|
|
if (true) {
|
|
return null; // Error.
|
|
} else {
|
|
return new Future<Null>.value(null); // Error.
|
|
}
|
|
}
|
|
}
|
|
|
|
main() {}
|