[vm] Ignore differences in generic-covariant-impl flags of type parameters when doing a subtype check

We might get different flags on lhs and rhs of a subtype check as
lhs might come from a tear-off which has generic-covariant-impl type
parameters and rhs is a standalone function type.

TEST=language/regress/regress46816_test
Fixes https://github.com/dart-lang/sdk/issues/46816

Change-Id: Ic0f1b4a9fdf0f4c9ae65c8c372d12c1e51ad8050
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209265
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov 2021-08-07 21:03:46 +00:00 committed by commit-bot@chromium.org
parent 9b67ccf7d8
commit 3097b72b2b
3 changed files with 43 additions and 3 deletions

View file

@ -8949,9 +8949,11 @@ bool FunctionType::HasSameTypeParametersAndBounds(const FunctionType& other,
}
}
}
// Compare flags (IsGenericCovariantImpl).
if (!Array::Equals(type_params.flags(), other_type_params.flags())) {
return false;
if (kind != TypeEquality::kInSubtypeTest) {
// Compare flags (IsGenericCovariantImpl).
if (!Array::Equals(type_params.flags(), other_type_params.flags())) {
return false;
}
}
}
return true;

View file

@ -0,0 +1,18 @@
// 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.
import 'package:expect/expect.dart';
class A<X extends num> {
void f<Y extends X>(Y y) {}
}
typedef Func = void Function<Y extends int>(Y);
main() {
A<num> a = new A<int>();
dynamic f = (a as A<int>).f;
Expect.isTrue(f is Func);
print(f as Func);
}

View file

@ -0,0 +1,20 @@
// 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.
// @dart=2.9
import 'package:expect/expect.dart';
class A<X extends num> {
void f<Y extends X>(Y y) {}
}
typedef Func = void Function<Y extends int>(Y);
main() {
A<num> a = new A<int>();
dynamic f = (a as A<int>).f;
Expect.isTrue(f is Func);
print(f as Func);
}