[vm] Fix equality of implicit static closures
There could be multiple instances of implicit static closures due to
instantiations at run time:
void foo<T>(T x) {}
void bar<T>() {
void Function(T) myfoo1 = foo;
void Function(T) myfoo2 = foo;
print(myfoo1 == myfoo2);
}
This change fixes equality to handle this case.
TEST=language/generic_methods/explicit_instantiated_tearoff_test
TEST=language/constructor/tear_off_test
Issue https://github.com/dart-lang/sdk/issues/46231
Issue https://github.com/dart-lang/sdk/issues/46487
Change-Id: I485acc5444d19860ef4d8ebeec2e540fe57776d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208981
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
diff --git a/runtime/lib/function.cc b/runtime/lib/function.cc
index 53ff1e6..eebce6d 100644
--- a/runtime/lib/function.cc
+++ b/runtime/lib/function.cc
@@ -50,24 +50,28 @@
}
// Closures that are not implicit instance closures are unique.
const auto& func_a = Function::Handle(zone, receiver.function());
- if (!func_a.IsImplicitInstanceClosureFunction()) {
+ if (!func_a.IsImplicitClosureFunction()) {
return false;
}
const auto& func_b = Function::Handle(zone, other_closure.function());
- if (!func_b.IsImplicitInstanceClosureFunction()) {
+ if (!func_b.IsImplicitClosureFunction()) {
return false;
}
// If the closure functions are not the same, check the function's name and
// owner, as multiple function objects could exist for the same function due
// to hot reload.
if (func_a.ptr() != func_b.ptr() &&
- (func_a.name() != func_b.name() || func_a.Owner() != func_b.Owner())) {
+ (func_a.name() != func_b.name() || func_a.Owner() != func_b.Owner() ||
+ func_a.is_static() != func_b.is_static())) {
return false;
}
- // Check that the both receiver instances are the same.
- const Context& context_a = Context::Handle(zone, receiver.context());
- const Context& context_b = Context::Handle(zone, other_closure.context());
- return context_a.At(0) == context_b.At(0);
+ if (!func_a.is_static()) {
+ // Check that the both receiver instances are the same.
+ const Context& context_a = Context::Handle(zone, receiver.context());
+ const Context& context_b = Context::Handle(zone, other_closure.context());
+ return context_a.At(0) == context_b.At(0);
+ }
+ return true;
}
DEFINE_NATIVE_ENTRY(Closure_equals, 0, 2) {