mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:16:51 +00:00
5efe55abf7
+ fix test to expect erasure of `S & int` to `S` also when bound is `dynamic`. Closes #43591 Change-Id: I44cb4c726648d4065bdf89bb2dbf71b2753c6c84 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169340 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
66 lines
1.6 KiB
Dart
66 lines
1.6 KiB
Dart
// Copyright (c) 2020, 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";
|
|
|
|
// Tests the resolution of a bare type variable with bounded or promoted type.
|
|
|
|
extension E<T> on T {
|
|
T Function(T) get f => (_) => this;
|
|
}
|
|
|
|
class A<S extends num> {
|
|
void testBoundedTypeVariable(S s) {
|
|
// Check that `num` has no `f` so E is applicable, then bind `T` to `S`.
|
|
S Function(S) f = s.f;
|
|
}
|
|
|
|
void testPromotedTypeVariable(S s) {
|
|
if (s is int) {
|
|
// Check that `int` has no `f`, erase `S & int` to `S`, bind `T` to `S`.
|
|
S Function(S) f = s.f;
|
|
}
|
|
}
|
|
}
|
|
|
|
class B<S extends dynamic> {
|
|
void testBoundedTypeVariable(S s) {
|
|
// `dynamic` considered to have `f`, E not applicable, dynamic invocation.
|
|
Expect.throws(() => s.f);
|
|
}
|
|
|
|
void testPromotedType(S s) {
|
|
if (s is int) {
|
|
// Check that `int` has no `f`, erase `S & int` to `S`, bind `T` to `S`.
|
|
S Function(S) f = s.f;
|
|
}
|
|
}
|
|
}
|
|
|
|
class C<S> {
|
|
void testBoundedTypeVariable(S s) {
|
|
// Check that `Object?` has no `f` so E is applicable, then bind `T` to `S`.
|
|
S Function(S) f = s.f;
|
|
}
|
|
|
|
void testPromotedType(S s) {
|
|
if (s is int) {
|
|
// Check that `int` has no `f`, bind `T` to `S`.
|
|
S Function(S) f = s.f;
|
|
}
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
A<int>()
|
|
..testBoundedTypeVariable(1)
|
|
..testPromotedTypeVariable(2);
|
|
B<int>()
|
|
..testBoundedTypeVariable(1)
|
|
..testPromotedType(2);
|
|
C<int>()
|
|
..testBoundedTypeVariable(1)
|
|
..testPromotedType(2);
|
|
}
|