[VM/runtime] Consider trail when comparing type parameter and bounds of function types.

Fixes https://github.com/dart-lang/sdk/issues/45443

TEST=added regression test

Change-Id: I82c581d9627d9eb1cf31d108a534fd4f5d6bb0a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192947
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
This commit is contained in:
Regis Crelier 2021-03-29 16:49:47 +00:00 committed by commit-bot@chromium.org
parent 0ab30e584b
commit e35ba5b9e3
3 changed files with 19 additions and 4 deletions

View file

@ -8554,7 +8554,8 @@ bool FunctionType::IsContravariantParameter(intptr_t parameter_position,
}
bool FunctionType::HasSameTypeParametersAndBounds(const FunctionType& other,
TypeEquality kind) const {
TypeEquality kind,
TrailPtr trail) const {
Thread* thread = Thread::Current();
Zone* zone = thread->zone();
@ -8574,7 +8575,7 @@ bool FunctionType::HasSameTypeParametersAndBounds(const FunctionType& other,
for (intptr_t i = 0; i < num_type_params; i++) {
type_param ^= type_params.TypeAt(i);
other_type_param ^= other_type_params.TypeAt(i);
if (!type_param.IsEquivalent(other_type_param, kind)) {
if (!type_param.IsEquivalent(other_type_param, kind, trail)) {
return false;
}
}
@ -20286,7 +20287,7 @@ bool FunctionType::IsEquivalent(const Instance& other,
// Compare function type parameters and their bounds.
// Check the type parameters and bounds of generic functions.
if (!HasSameTypeParametersAndBounds(other_type, kind)) {
if (!HasSameTypeParametersAndBounds(other_type, kind, trail)) {
return false;
}
AbstractType& param_type = Type::Handle(zone);

View file

@ -8224,7 +8224,8 @@ class FunctionType : public AbstractType {
// with equal bounds as the other function type. Type parameter names and
// parameter names (unless optional named) are ignored.
bool HasSameTypeParametersAndBounds(const FunctionType& other,
TypeEquality kind) const;
TypeEquality kind,
TrailPtr trail = nullptr) const;
// Return true if this function type declares type parameters.
bool IsGeneric() const { return NumTypeParameters(Thread::Current()) > 0; }

View file

@ -0,0 +1,13 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=generic-metadata
class C1<T extends void Function<TT extends T>()> {}
class C2<T extends TT Function<TT extends T>()> {}
main() {
print("OK");
}