@@ -10011,12 +10011,8 @@ ObjectPtr Function::DoArgumentTypesMatch(
1001110011 const TypeArguments& function_type_args) -> bool {
1001210012 // If the argument type is the top type, no need to check.
1001310013 if (type.IsTopTypeForSubtyping()) return true;
10014- if (argument.IsNull()) {
10015- return Instance::NullIsAssignableTo(type, instantiator_type_args,
10016- function_type_args);
10017- }
10018- return argument.IsAssignableTo(type, instantiator_type_args,
10019- function_type_args);
10014+ return argument.IsInstanceOf(type, instantiator_type_args,
10015+ function_type_args);
1002010016 };
1002110017
1002210018 // Check types of the provided arguments against the expected parameter types.
@@ -21342,88 +21338,15 @@ void Instance::SetTypeArguments(const TypeArguments& value) const {
2134221338 SetFieldAtOffset(field_offset, value);
2134321339}
2134421340
21345- /*
21346- Specification of instance checks (e is T) and casts (e as T), where e evaluates
21347- to a value v and v has runtime type S:
21348-
21349- Instance checks (e is T) in weak checking mode in a legacy or opted-in library:
21350- If v == null and T is a legacy type
21351- return LEGACY_SUBTYPE(T, Null) || LEGACY_SUBTYPE(Object, T)
21352- If v == null and T is not a legacy type, return NNBD_SUBTYPE(Null, T)
21353- Otherwise return LEGACY_SUBTYPE(S, T)
21354-
21355- Instance checks (e is T) in strong checking mode in a legacy or opted-in lib:
21356- If v == null and T is a legacy type
21357- return LEGACY_SUBTYPE(T, Null) || LEGACY_SUBTYPE(Object, T)
21358- Otherwise return NNBD_SUBTYPE(S, T)
21359-
21360- Casts (e as T) in weak checking mode in a legacy or opted-in library:
21361- If LEGACY_SUBTYPE(S, T) then e as T evaluates to v.
21362- Otherwise a TypeError is thrown.
21363-
21364- Casts (e as T) in strong checking mode in a legacy or opted-in library:
21365- If NNBD_SUBTYPE(S, T) then e as T evaluates to v.
21366- Otherwise a TypeError is thrown.
21367- */
21368-
2136921341bool Instance::IsInstanceOf(
2137021342 const AbstractType& other,
2137121343 const TypeArguments& other_instantiator_type_arguments,
2137221344 const TypeArguments& other_function_type_arguments) const {
2137321345 ASSERT(!other.IsDynamicType());
21374- if (IsNull()) {
21375- return Instance::NullIsInstanceOf(other, other_instantiator_type_arguments,
21376- other_function_type_arguments);
21377- }
21378- // In strong mode, compute NNBD_SUBTYPE(runtimeType, other).
21379- // In weak mode, compute LEGACY_SUBTYPE(runtimeType, other).
21380- return RuntimeTypeIsSubtypeOf(other, other_instantiator_type_arguments,
21381- other_function_type_arguments);
21382- }
21383-
21384- bool Instance::IsAssignableTo(
21385- const AbstractType& other,
21386- const TypeArguments& other_instantiator_type_arguments,
21387- const TypeArguments& other_function_type_arguments) const {
21388- ASSERT(!other.IsDynamicType());
21389- // In strong mode, compute NNBD_SUBTYPE(runtimeType, other).
21390- // In weak mode, compute LEGACY_SUBTYPE(runtimeType, other).
2139121346 return RuntimeTypeIsSubtypeOf(other, other_instantiator_type_arguments,
2139221347 other_function_type_arguments);
2139321348}
2139421349
21395- // If 'other' type (once instantiated) is a legacy type:
21396- // return LEGACY_SUBTYPE(other, Null) || LEGACY_SUBTYPE(Object, other).
21397- // Otherwise return NNBD_SUBTYPE(Null, T).
21398- // Ignore value of strong flag value.
21399- bool Instance::NullIsInstanceOf(
21400- const AbstractType& other,
21401- const TypeArguments& other_instantiator_type_arguments,
21402- const TypeArguments& other_function_type_arguments) {
21403- ASSERT(other.IsFinalized());
21404- if (other.IsNullable()) {
21405- // This case includes top types (void, dynamic, Object?).
21406- // The uninstantiated nullable type will remain nullable after
21407- // instantiation.
21408- return true;
21409- }
21410- if (other.IsFutureOrType()) {
21411- const auto& type = AbstractType::Handle(other.UnwrapFutureOr());
21412- return NullIsInstanceOf(type, other_instantiator_type_arguments,
21413- other_function_type_arguments);
21414- }
21415- // No need to instantiate type, unless it is a type parameter.
21416- // Note that a typeref cannot refer to a type parameter.
21417- if (other.IsTypeParameter()) {
21418- auto& type = AbstractType::Handle(other.InstantiateFrom(
21419- other_instantiator_type_arguments, other_function_type_arguments,
21420- kAllFree, Heap::kOld));
21421- return Instance::NullIsInstanceOf(type, Object::null_type_arguments(),
21422- Object::null_type_arguments());
21423- }
21424- return false;
21425- }
21426-
2142721350// Must be kept in sync with GenerateNullIsAssignableToType in
2142821351// stub_code_compiler.cc if any changes are made.
2142921352bool Instance::NullIsAssignableTo(const AbstractType& other) {
0 commit comments