Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9b67ccf

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[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 dart-lang/sdk#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 <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 4d4f69a commit 9b67ccf

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

runtime/lib/function.cc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ static bool ClosureEqualsHelper(Zone* zone,
4040
return false;
4141
}
4242
const auto& other_closure = Closure::Cast(other);
43-
// Check that the delayed type argument vectors match.
44-
if (receiver.delayed_type_arguments() !=
45-
other_closure.delayed_type_arguments()) {
46-
// Mismatches should only happen when a generic function is involved.
47-
ASSERT(Function::Handle(receiver.function()).IsGeneric() ||
48-
Function::Handle(other_closure.function()).IsGeneric());
49-
return false;
50-
}
5143
// Closures that are not implicit closures (tear-offs) are unique.
5244
const auto& func_a = Function::Handle(zone, receiver.function());
5345
if (!func_a.IsImplicitClosureFunction()) {
@@ -65,6 +57,21 @@ static bool ClosureEqualsHelper(Zone* zone,
6557
func_a.is_static() != func_b.is_static())) {
6658
return false;
6759
}
60+
// Check that the delayed type argument vectors match.
61+
if (receiver.delayed_type_arguments() !=
62+
other_closure.delayed_type_arguments()) {
63+
// Mismatches should only happen when a generic function is involved.
64+
ASSERT(func_a.IsGeneric() || func_b.IsGeneric());
65+
const auto& type_args_a =
66+
TypeArguments::Handle(zone, receiver.delayed_type_arguments());
67+
const auto& type_args_b =
68+
TypeArguments::Handle(zone, other_closure.delayed_type_arguments());
69+
if (type_args_a.IsNull() || type_args_b.IsNull() ||
70+
(type_args_a.Length() != type_args_b.Length()) ||
71+
!type_args_a.IsEquivalent(type_args_b, TypeEquality::kSyntactical)) {
72+
return false;
73+
}
74+
}
6875
if (!func_a.is_static()) {
6976
// Check that the both receiver instances are the same.
7077
const Context& context_a = Context::Handle(zone, receiver.context());

0 commit comments

Comments
 (0)