[vm] Handle equal but not identical type args when comparing instantiated tear-offs

It is possible to instantiate a tear-off of generic function with type
arguments which are equivalent (equal) but not identical, for example
[int] and [int*]. So, operator== on closures changed to compare
delayed type arguments of implicit closures for equality.

Fixes https://github.com/dart-lang/sdk/issues/46836
TEST=language/closure/identity_equality_tearoff_test (in weak mode)

Change-Id: I610eb226a7a244deb6415f8d92f74e941371bb50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209266
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov 2021-08-07 20:49:27 +00:00 committed by commit-bot@chromium.org
parent 4d4f69ab95
commit 9b67ccf7d8

View file

@ -40,14 +40,6 @@ static bool ClosureEqualsHelper(Zone* zone,
return false;
}
const auto& other_closure = Closure::Cast(other);
// Check that the delayed type argument vectors match.
if (receiver.delayed_type_arguments() !=
other_closure.delayed_type_arguments()) {
// Mismatches should only happen when a generic function is involved.
ASSERT(Function::Handle(receiver.function()).IsGeneric() ||
Function::Handle(other_closure.function()).IsGeneric());
return false;
}
// Closures that are not implicit closures (tear-offs) are unique.
const auto& func_a = Function::Handle(zone, receiver.function());
if (!func_a.IsImplicitClosureFunction()) {
@ -65,6 +57,21 @@ static bool ClosureEqualsHelper(Zone* zone,
func_a.is_static() != func_b.is_static())) {
return false;
}
// Check that the delayed type argument vectors match.
if (receiver.delayed_type_arguments() !=
other_closure.delayed_type_arguments()) {
// Mismatches should only happen when a generic function is involved.
ASSERT(func_a.IsGeneric() || func_b.IsGeneric());
const auto& type_args_a =
TypeArguments::Handle(zone, receiver.delayed_type_arguments());
const auto& type_args_b =
TypeArguments::Handle(zone, other_closure.delayed_type_arguments());
if (type_args_a.IsNull() || type_args_b.IsNull() ||
(type_args_a.Length() != type_args_b.Length()) ||
!type_args_a.IsEquivalent(type_args_b, TypeEquality::kSyntactical)) {
return false;
}
}
if (!func_a.is_static()) {
// Check that the both receiver instances are the same.
const Context& context_a = Context::Handle(zone, receiver.context());