mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:37:12 +00:00
[test] Fix constructor tear off tests in language
Change-Id: Icf5f6e99df68cd4194e9f4d9314757eab3d3fe11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207661 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
This commit is contained in:
parent
f2f21499e7
commit
51d10c8c04
|
@ -24,18 +24,16 @@ class NGenRedir {
|
|||
const NGenRedir._(this.x);
|
||||
}
|
||||
|
||||
class NFac {
|
||||
class NFac implements NFacRedir {
|
||||
final int x;
|
||||
factory NFac(int x) => NFacRedir._(x);
|
||||
factory NFac.named(int x) => NFacRedir._(x);
|
||||
NFac._(this.x);
|
||||
factory NFac(int x) => NFac._(x);
|
||||
factory NFac.named(int x) => NFac._(x);
|
||||
const NFac._(this.x);
|
||||
}
|
||||
|
||||
class NFacRedir {
|
||||
final int x;
|
||||
const factory NFacRedir(int x) = NFac._;
|
||||
const factory NFacRedir.named(int x) = NFac._;
|
||||
NFacRedir._(this.x);
|
||||
}
|
||||
|
||||
// Generic classes.
|
||||
|
@ -52,18 +50,16 @@ class GGenRedir<T> {
|
|||
const GGenRedir._(this.x);
|
||||
}
|
||||
|
||||
class GFac<T> {
|
||||
class GFac<T> implements GFacRedir<T> {
|
||||
final int x;
|
||||
factory GFac(int x) => GFacRedir._(x);
|
||||
factory GFac.named(int x) => GFacRedir._(x);
|
||||
GFac._(this.x);
|
||||
factory GFac(int x) => GFac._(x);
|
||||
factory GFac.named(int x) => GFac._(x);
|
||||
const GFac._(this.x);
|
||||
}
|
||||
|
||||
class GFacRedir<T> {
|
||||
final int x;
|
||||
const factory GFacRedir(int x) = GFac._;
|
||||
const factory GFacRedir.named(int x) = GFac._;
|
||||
GFacRedir._(this.x);
|
||||
}
|
||||
|
||||
class Optional<T> {
|
||||
|
@ -96,9 +92,9 @@ void main() {
|
|||
GGen<int>.new.expectStaticType<Exactly<GGen<int> Function(int)>>();
|
||||
GGen<int>.named.expectStaticType<Exactly<GGen<int> Function(int)>>();
|
||||
GGenRedir<int>.new
|
||||
.expectStaticType<Exactly<GGenRedir<T> Function<T>(int)>>();
|
||||
.expectStaticType<Exactly<GGenRedir<int> Function(int)>>();
|
||||
GGenRedir<int>.named
|
||||
.expectStaticType<Exactly<GGenRedir<T> Function<T>(int)>>();
|
||||
.expectStaticType<Exactly<GGenRedir<int> Function(int)>>();
|
||||
GFac<int>.new.expectStaticType<Exactly<GFac<int> Function(int)>>();
|
||||
GFac<int>.named.expectStaticType<Exactly<GFac<int> Function(int)>>();
|
||||
GFacRedir<int>.new
|
||||
|
@ -106,26 +102,26 @@ void main() {
|
|||
GFacRedir<int>.named
|
||||
.expectStaticType<Exactly<GFacRedir<int> Function(int)>>();
|
||||
|
||||
contextType<GGen<int> Function(int)>(
|
||||
context<GGen<int> Function(int)>(
|
||||
GGen.new..expectStaticType<Exactly<GGen<int> Function(int)>>());
|
||||
contextType<GGen<int> Function(int)>(
|
||||
context<GGen<int> Function(int)>(
|
||||
GGen.named..expectStaticType<Exactly<GGen<int> Function(int)>>());
|
||||
contextType<GGenRedir<int> Function(int)>(GGenRedir.new
|
||||
context<GGenRedir<int> Function(int)>(GGenRedir.new
|
||||
..expectStaticType<Exactly<GGenRedir<int> Function(int)>>());
|
||||
contextType<GGenRedir<int> Function(int)>(GGenRedir.named
|
||||
context<GGenRedir<int> Function(int)>(GGenRedir.named
|
||||
..expectStaticType<Exactly<GGenRedir<int> Function(int)>>());
|
||||
contextType<GFac<int> Function(int)>(
|
||||
context<GFac<int> Function(int)>(
|
||||
GFac.new..expectStaticType<Exactly<GFac<int> Function(int)>>());
|
||||
contextType<GFac<int> Function(int)>(
|
||||
context<GFac<int> Function(int)>(
|
||||
GFac.named..expectStaticType<Exactly<GFac<int> Function(int)>>());
|
||||
contextType<GFacRedir<int> Function(int)>(
|
||||
context<GFacRedir<int> Function(int)>(
|
||||
GFacRedir.new..expectStaticType<Exactly<GFacRedir<int> Function(int)>>());
|
||||
contextType<GFacRedir<int> Function(int)>(GFacRedir.named
|
||||
context<GFacRedir<int> Function(int)>(GFacRedir.named
|
||||
..expectStaticType<Exactly<GFacRedir<int> Function(int)>>());
|
||||
|
||||
contextType<Optional<int> Function()>(Optional.new
|
||||
context<Optional<int> Function()>(Optional.new
|
||||
..expectStaticType<Exactly<Optional<int> Function([int, int])>>());
|
||||
contextType<Optional<int> Function()>(Optional.named
|
||||
context<Optional<int> Function()>(Optional.named
|
||||
..expectStaticType<Exactly<Optional<int> Function({int x, int y})>>());
|
||||
|
||||
// Check that tear-offs are canonicalized where possible
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
Type typeOf<T>() => T;
|
||||
|
||||
/// Ensures a context type of [T] for the operand.
|
||||
void context<T>(T x) {}
|
||||
Object? context<T>(T x) => x;
|
||||
|
||||
/// Captures the context type of the call and returns the same type.
|
||||
///
|
||||
|
|
|
@ -18,8 +18,8 @@ class C<T extends num> {}
|
|||
Type type<T>() => T;
|
||||
|
||||
void main() {
|
||||
C.expectStaticType<Type>();
|
||||
C<int>.expectStaticType<Type>();
|
||||
(C).expectStaticType<Exactly<Type>>();
|
||||
(C<int>).expectStaticType<Exactly<Type>>();
|
||||
|
||||
Expect.identical(C<num>, C);
|
||||
Expect.identical(C<int>, C<int>);
|
||||
|
@ -30,8 +30,8 @@ void main() {
|
|||
Expect.identical(C<dynamic>, C<dynamic>);
|
||||
Expect.equals(C<dynamic>, type<C<dynamic>>());
|
||||
|
||||
prefix.C.expectStaticType<Type>();
|
||||
prefix.C<int>.expectStaticType<Type>();
|
||||
(prefix.C).expectStaticType<Exactly<Type>>();
|
||||
(prefix.C<int>).expectStaticType<Exactly<Type>>();
|
||||
|
||||
Expect.identical(prefix.C<num>, prefix.C);
|
||||
Expect.identical(prefix.C<int>, prefix.C<int>);
|
||||
|
|
|
@ -14,7 +14,7 @@ import "../static_type_helper.dart";
|
|||
void use(Type type) {}
|
||||
|
||||
class C<T> {
|
||||
final T value;
|
||||
final T x;
|
||||
C(this.x);
|
||||
C.named(this.x);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ void main() {
|
|||
// or if instantiated with a constant type.
|
||||
const List<Object> constructors = [
|
||||
Special.new,
|
||||
Spceial.named,
|
||||
Special.named,
|
||||
Direct.new,
|
||||
Direct.named,
|
||||
Bounded.new,
|
||||
|
@ -64,12 +64,12 @@ void main() {
|
|||
Wrapping.new,
|
||||
Wrapping.named,
|
||||
],
|
||||
const <C<int, int> Function(C<int>)>[
|
||||
const <C<int> Function(int)>[
|
||||
Extra.new,
|
||||
Extra.named,
|
||||
]
|
||||
];
|
||||
Expect.notNull(constructors); // Use variable.
|
||||
Expect.isNotNull(constructors); // Use variable.
|
||||
|
||||
// The static type is as expected.
|
||||
|
||||
|
@ -83,8 +83,8 @@ void main() {
|
|||
Bounded.new.expectStaticType<Exactly<C<T> Function<T extends num>(T)>>();
|
||||
Bounded.named.expectStaticType<Exactly<C<T> Function<T extends num>(T)>>();
|
||||
|
||||
Wrapping.new.expectStaticType<Exactly<C<C<T>> Function<T>(T)>>();
|
||||
Wrapping.named.expectStaticType<Exactly<C<C<T>> Function<T>(T)>>();
|
||||
Wrapping.new.expectStaticType<Exactly<C<C<T>> Function<T>(C<T>)>>();
|
||||
Wrapping.named.expectStaticType<Exactly<C<C<T>> Function<T>(C<T>)>>();
|
||||
|
||||
Extra.new.expectStaticType<Exactly<C<T> Function<T, S>(T)>>();
|
||||
Extra.named.expectStaticType<Exactly<C<T> Function<T, S>(T)>>();
|
||||
|
@ -105,24 +105,24 @@ void main() {
|
|||
Extra<int, String>.named.expectStaticType<Exactly<C<int> Function(int)>>();
|
||||
|
||||
// Implicitly instantiated.
|
||||
contextType<C<int> Function(int)>(
|
||||
Direct<int>.new..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
contextType<C<int> Function(int)>(
|
||||
Direct<int>.named..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
context<C<int> Function(int)>(
|
||||
Direct.new..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
context<C<int> Function(int)>(
|
||||
Direct.named..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
|
||||
contextType<C<int> Function(int)>(
|
||||
Bounded<int>.new..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
contextType<C<int> Function(int)>(
|
||||
Bounded<int>.named..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
context<C<int> Function(int)>(
|
||||
Bounded.new..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
context<C<int> Function(int)>(
|
||||
Bounded.named..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
|
||||
contextType<C<C<int>> Function(C<int>)>(Wrapping<int>.new
|
||||
context<C<C<int>> Function(C<int>)>(Wrapping.new
|
||||
..expectStaticType<Exactly<C<C<int>> Function(C<int>)>>());
|
||||
contextType<C<C<int>> Function(C<int>)>(Wrapping<int>.named
|
||||
context<C<C<int>> Function(C<int>)>(Wrapping.named
|
||||
..expectStaticType<Exactly<C<C<int>> Function(C<int>)>>());
|
||||
|
||||
contextType<C<int, String> Function(int)>(Extra<int, String>.new
|
||||
context<C<int> Function(int)>(Extra.new
|
||||
..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
contextType<C<int, String> Function(int)>(Extra<int, String>.named
|
||||
context<C<int> Function(int)>(Extra.named
|
||||
..expectStaticType<Exactly<C<int> Function(int)>>());
|
||||
|
||||
// Uninstantiated tear-offs always canonicalize.
|
||||
|
@ -176,35 +176,35 @@ void main() {
|
|||
|
||||
// Implicit instantiation.
|
||||
Expect.identical(
|
||||
contextType<C<int> Function(int)>(Direct.new),
|
||||
context<C<int> Function(int)>(Direct.new),
|
||||
C<int>.new,
|
||||
);
|
||||
Expect.identical(
|
||||
contextType<C<int> Function(int)>(Direct.named),
|
||||
context<C<int> Function(int)>(Direct.named),
|
||||
C<int>.named,
|
||||
);
|
||||
Expect.identical(
|
||||
contextType<C<int> Function(int)>(Bounded.new),
|
||||
context<C<int> Function(int)>(Bounded.new),
|
||||
C<int>.new,
|
||||
);
|
||||
Expect.identical(
|
||||
contextType<C<int> Function(int)>(Bounded.named),
|
||||
context<C<int> Function(int)>(Bounded.named),
|
||||
C<int>.named,
|
||||
);
|
||||
Expect.identical(
|
||||
contextType<C<C<int>> Function(C<int>)>(Wrapping.new),
|
||||
context<C<C<int>> Function(C<int>)>(Wrapping.new),
|
||||
C<C<int>>.new,
|
||||
);
|
||||
Expect.identical(
|
||||
contextType<C<C<int>> Function(C<int>)>(Wrapping.named),
|
||||
context<C<C<int>> Function(C<int>)>(Wrapping.named),
|
||||
C<C<int>>.named,
|
||||
);
|
||||
Expect.identical(
|
||||
contextType<D<int, String> Function()>(Swapped.new),
|
||||
context<D<int, String> Function()>(Swapped.new),
|
||||
D<int, String>.new,
|
||||
);
|
||||
Expect.identical(
|
||||
contextType<D<int, String> Function()>(Swapped.named),
|
||||
context<D<int, String> Function()>(Swapped.named),
|
||||
D<int, String>.named,
|
||||
);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
import "package:expect/expect.dart";
|
||||
|
||||
class C<T> {
|
||||
final T value;
|
||||
final T x;
|
||||
C(this.x);
|
||||
C.named(this.x);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ void main() {
|
|||
Expect.identical(e2, co);
|
||||
Expect.identical(e3, ci);
|
||||
|
||||
(<T>() {
|
||||
(<T extends num>() {
|
||||
// Using a non-constant type.
|
||||
Expect.equals(Direct<T>, ci);
|
||||
Expect.equals(Bounded<T>, ci);
|
||||
|
|
Loading…
Reference in a new issue