mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:01:42 +00:00
[vm/nnbd] Fix CompileType::IsAssignableTo for nullable types in strong mode
Also, tests/corelib/string_operations_with_null_test.dart is fixed for strong mode: in strong mode TypeError is thrown when null is casted to a non-nullable type; in weak mode null is silently passed and ArgumentError or NoSuchMethodError is thrown. Change-Id: I566a80293ffb03752cc3409e1b79491f0aff6888 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140779 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
2323087237
commit
e0b7841d16
|
@ -815,17 +815,13 @@ bool CompileType::IsAssignableTo(const AbstractType& other) {
|
|||
if (other.IsTopTypeForAssignability()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsNone()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Consider the compile type of the value.
|
||||
const AbstractType& compile_type = *ToAbstractType();
|
||||
if (compile_type.IsNullType()) {
|
||||
return Instance::NullIsAssignableTo(other);
|
||||
if (is_nullable() && !Instance::NullIsAssignableTo(other)) {
|
||||
return false;
|
||||
}
|
||||
return compile_type.IsSubtypeOf(other, Heap::kOld);
|
||||
return ToAbstractType()->IsSubtypeOf(other, Heap::kOld);
|
||||
}
|
||||
|
||||
bool CompileType::IsInstanceOf(const AbstractType& other) {
|
||||
|
|
|
@ -11,7 +11,8 @@ returnStringOrNull() {
|
|||
}
|
||||
|
||||
main() {
|
||||
Expect.throwsArgumentError(() => 'foo' + returnStringOrNull());
|
||||
Expect.throws(() => 'foo' + returnStringOrNull(),
|
||||
(e) => e is ArgumentError || e is TypeError);
|
||||
Expect.throws(() => 'foo'.split(returnStringOrNull()),
|
||||
(e) => e is ArgumentError || e is NoSuchMethodError);
|
||||
(e) => e is ArgumentError || e is NoSuchMethodError || e is TypeError);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue