mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
[ddc] Delete variance tests for old DDC types
- These tests rely on the internals of the old type system. - Copy some expectations to the language suite when it looks like there isn't already coverage for the same test. Change-Id: I63bfa2bc94fb29b4e4f90c3c02cf0943d19764b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352463 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Kallen Tu <kallentu@google.com>
This commit is contained in:
parent
ea8efc6fc1
commit
b955d6a628
|
@ -1,190 +0,0 @@
|
||||||
// Copyright (c) 2019, 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=variance
|
|
||||||
|
|
||||||
// Tests runtime subtyping with explicit variance modifiers.
|
|
||||||
|
|
||||||
import 'dart:_foreign_helper' show TYPE_REF;
|
|
||||||
import 'dart:async' show FutureOr;
|
|
||||||
|
|
||||||
import 'runtime_utils.dart';
|
|
||||||
|
|
||||||
class Upper {}
|
|
||||||
|
|
||||||
class Middle extends Upper {}
|
|
||||||
|
|
||||||
class Lower extends Middle {}
|
|
||||||
|
|
||||||
class Covariant<out T> {}
|
|
||||||
|
|
||||||
class Contravariant<in T> {}
|
|
||||||
|
|
||||||
class Invariant<inout T> {}
|
|
||||||
|
|
||||||
class LegacyCovariant<T> {}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
// Covariant<Lower> <: Covariant<Middle>
|
|
||||||
checkProperSubtype(
|
|
||||||
TYPE_REF<Covariant<Lower>>(), TYPE_REF<Covariant<Middle>>());
|
|
||||||
|
|
||||||
// Covariant<Middle> <: Covariant<Middle>
|
|
||||||
checkSubtype(TYPE_REF<Covariant<Middle>>(), TYPE_REF<Covariant<Middle>>());
|
|
||||||
|
|
||||||
// Contravariant<Upper> <: Contravariant<Middle>
|
|
||||||
checkProperSubtype(
|
|
||||||
TYPE_REF<Contravariant<Upper>>(), TYPE_REF<Contravariant<Middle>>());
|
|
||||||
|
|
||||||
// Contravariant<Middle> <: Contravariant<Middle>
|
|
||||||
checkSubtype(
|
|
||||||
TYPE_REF<Contravariant<Middle>>(), TYPE_REF<Contravariant<Middle>>());
|
|
||||||
|
|
||||||
// Invariant<Middle> <: Invariant<Middle>
|
|
||||||
checkSubtype(TYPE_REF<Invariant<Middle>>(), TYPE_REF<Invariant<Middle>>());
|
|
||||||
|
|
||||||
// Invariant<dynamic> <:> Invariant<Object?>
|
|
||||||
checkMutualSubtype(
|
|
||||||
TYPE_REF<Invariant<dynamic>>(), TYPE_REF<Invariant<Object?>>());
|
|
||||||
|
|
||||||
// Invariant<FutureOr<dynamic>> <:> Invariant<dynamic>
|
|
||||||
checkMutualSubtype(
|
|
||||||
TYPE_REF<Invariant<FutureOr<dynamic>>>(), TYPE_REF<Invariant<dynamic>>());
|
|
||||||
|
|
||||||
// Invariant<FutureOr<Null>> <:> Invariant<Future<Null>?>
|
|
||||||
checkMutualSubtype(TYPE_REF<Invariant<FutureOr<Null>>>(),
|
|
||||||
TYPE_REF<Invariant<Future<Null>?>>());
|
|
||||||
|
|
||||||
// LegacyCovariant<Lower> <: LegacyCovariant<Middle>
|
|
||||||
checkProperSubtype(
|
|
||||||
TYPE_REF<LegacyCovariant<Lower>>(), TYPE_REF<LegacyCovariant<Middle>>());
|
|
||||||
|
|
||||||
// List<Covariant<Lower>> <: Iterable<Covariant<Middle>>
|
|
||||||
checkProperSubtype(TYPE_REF<List<Covariant<Lower>>>(),
|
|
||||||
TYPE_REF<Iterable<Covariant<Middle>>>());
|
|
||||||
|
|
||||||
// List<Contravariant<Upper>> <: Iterable<Contravariant<Middle>>
|
|
||||||
checkProperSubtype(TYPE_REF<List<Contravariant<Upper>>>(),
|
|
||||||
TYPE_REF<Iterable<Contravariant<Middle>>>());
|
|
||||||
|
|
||||||
// List<Invariant<Middle>> <: Iterable<Invariant<Middle>>
|
|
||||||
checkProperSubtype(TYPE_REF<List<Invariant<Middle>>>(),
|
|
||||||
TYPE_REF<Iterable<Invariant<Middle>>>());
|
|
||||||
|
|
||||||
// List<LegacyCovariant<Lower>> <: Iterable<LegacyCovariant<Middle>>
|
|
||||||
checkProperSubtype(TYPE_REF<List<LegacyCovariant<Lower>>>(),
|
|
||||||
TYPE_REF<Iterable<LegacyCovariant<Middle>>>());
|
|
||||||
|
|
||||||
// String -> Covariant<Lower> <: String -> Covariant<Middle>
|
|
||||||
checkProperSubtype(TYPE_REF<Covariant<Lower> Function(String)>(),
|
|
||||||
TYPE_REF<Covariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// Covariant<Upper> -> String <: Covariant<Middle> -> String
|
|
||||||
checkProperSubtype(TYPE_REF<String Function(Covariant<Upper>)>(),
|
|
||||||
TYPE_REF<String Function(Covariant<Middle>)>());
|
|
||||||
|
|
||||||
// String -> Contravariant<Upper> <: String -> Contravariant<Middle>
|
|
||||||
checkProperSubtype(TYPE_REF<Contravariant<Upper> Function(String)>(),
|
|
||||||
TYPE_REF<Contravariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// Contravariant<Lower> -> String <: Contravariant<Middle> -> String
|
|
||||||
checkProperSubtype(TYPE_REF<String Function(Contravariant<Lower>)>(),
|
|
||||||
TYPE_REF<String Function(Contravariant<Middle>)>());
|
|
||||||
|
|
||||||
// String -> Invariant<Middle> <: String -> Invariant<Middle>
|
|
||||||
checkSubtype(TYPE_REF<String Function(Invariant<Middle>)>(),
|
|
||||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
|
||||||
|
|
||||||
// Invariant<Middle> -> String <: Invariant<Middle> -> String
|
|
||||||
checkSubtype(TYPE_REF<String Function(Invariant<Middle>)>(),
|
|
||||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
|
||||||
|
|
||||||
// String -> LegacyCovariant<Lower> <: String -> LegacyCovariant<Middle>
|
|
||||||
checkProperSubtype(TYPE_REF<LegacyCovariant<Lower> Function(String)>(),
|
|
||||||
TYPE_REF<LegacyCovariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// LegacyCovariant<Upper> -> String <: LegacyCovariant<Middle> -> String
|
|
||||||
checkProperSubtype(TYPE_REF<String Function(LegacyCovariant<Upper>)>(),
|
|
||||||
TYPE_REF<String Function(LegacyCovariant<Middle>)>());
|
|
||||||
|
|
||||||
// Covariant<Upper> </: Covariant<Middle>
|
|
||||||
checkSubtypeFailure(
|
|
||||||
TYPE_REF<Covariant<Upper>>(), TYPE_REF<Covariant<Middle>>());
|
|
||||||
|
|
||||||
// Contravariant<Lower> </: Contravariant<Middle>
|
|
||||||
checkSubtypeFailure(
|
|
||||||
TYPE_REF<Contravariant<Lower>>(), TYPE_REF<Contravariant<Middle>>());
|
|
||||||
|
|
||||||
// Invariant<Upper> </: Invariant<Middle>
|
|
||||||
checkSubtypeFailure(
|
|
||||||
TYPE_REF<Invariant<Upper>>(), TYPE_REF<Invariant<Middle>>());
|
|
||||||
|
|
||||||
// Invariant<Lower> </: Invariant<Middle>
|
|
||||||
checkSubtypeFailure(
|
|
||||||
TYPE_REF<Invariant<Lower>>(), TYPE_REF<Invariant<Middle>>());
|
|
||||||
|
|
||||||
// LegacyCovariant<Upper> </: LegacyCovariant<Middle>
|
|
||||||
checkSubtypeFailure(
|
|
||||||
TYPE_REF<LegacyCovariant<Upper>>(), TYPE_REF<LegacyCovariant<Middle>>());
|
|
||||||
|
|
||||||
// List<Covariant<Upper>> </: Iterable<Covariant<Middle>>
|
|
||||||
checkSubtypeFailure(TYPE_REF<List<Covariant<Upper>>>(),
|
|
||||||
TYPE_REF<Iterable<Covariant<Middle>>>());
|
|
||||||
|
|
||||||
// List<Contravariant<Lower>> </: Iterable<Contravariant<Middle>>
|
|
||||||
checkSubtypeFailure(TYPE_REF<List<Contravariant<Lower>>>(),
|
|
||||||
TYPE_REF<Iterable<Contravariant<Middle>>>());
|
|
||||||
|
|
||||||
// List<Invariant<Upper>> </: Iterable<Invariant<Middle>>
|
|
||||||
checkSubtypeFailure(TYPE_REF<List<Invariant<Upper>>>(),
|
|
||||||
TYPE_REF<Iterable<Invariant<Middle>>>());
|
|
||||||
|
|
||||||
// List<Invariant<Lower>> </: Iterable<Invariant<Middle>>
|
|
||||||
checkSubtypeFailure(TYPE_REF<List<Invariant<Lower>>>(),
|
|
||||||
TYPE_REF<Iterable<Invariant<Middle>>>());
|
|
||||||
|
|
||||||
// List<LegacyCovariant<Upper>> </: Iterable<LegacyCovariant<Middle>>
|
|
||||||
checkSubtypeFailure(TYPE_REF<List<LegacyCovariant<Upper>>>(),
|
|
||||||
TYPE_REF<Iterable<LegacyCovariant<Middle>>>());
|
|
||||||
|
|
||||||
// String -> Covariant<Upper> </: String -> Covariant<Middle>
|
|
||||||
checkSubtypeFailure(TYPE_REF<Covariant<Upper> Function(String)>(),
|
|
||||||
TYPE_REF<Covariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// Covariant<Lower> -> String </: Covariant<Middle> -> String
|
|
||||||
checkSubtypeFailure(TYPE_REF<String Function(Covariant<Lower>)>(),
|
|
||||||
TYPE_REF<String Function(Covariant<Middle>)>());
|
|
||||||
|
|
||||||
// String -> Contravariant<Lower> </: String -> Contravariant<Middle>
|
|
||||||
checkSubtypeFailure(TYPE_REF<Contravariant<Lower> Function(String)>(),
|
|
||||||
TYPE_REF<Contravariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// Contravariant<Upper> -> String </: Contravariant<Middle> -> String
|
|
||||||
checkSubtypeFailure(TYPE_REF<String Function(Contravariant<Upper>)>(),
|
|
||||||
TYPE_REF<String Function(Contravariant<Middle>)>());
|
|
||||||
|
|
||||||
// String -> Invariant<Upper> </: String -> Invariant<Middle>
|
|
||||||
checkSubtypeFailure(TYPE_REF<Invariant<Upper> Function(String)>(),
|
|
||||||
TYPE_REF<Invariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// Invariant<Upper> -> String </: Invariant<Middle> -> String
|
|
||||||
checkSubtypeFailure(TYPE_REF<String Function(Invariant<Upper>)>(),
|
|
||||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
|
||||||
|
|
||||||
// String -> Invariant<Lower> </: String -> Invariant<Middle>
|
|
||||||
checkSubtypeFailure(TYPE_REF<Invariant<Lower> Function(String)>(),
|
|
||||||
TYPE_REF<Invariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// Invariant<Lower> -> String <: Invariant<Middle> -> String
|
|
||||||
checkSubtypeFailure(TYPE_REF<String Function(Invariant<Lower>)>(),
|
|
||||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
|
||||||
|
|
||||||
// String -> LegacyCovariant<Upper> </: String -> LegacyCovariant<Middle>
|
|
||||||
checkSubtypeFailure(TYPE_REF<LegacyCovariant<Upper> Function(String)>(),
|
|
||||||
TYPE_REF<LegacyCovariant<Middle> Function(String)>());
|
|
||||||
|
|
||||||
// LegacyCovariant<Lower> -> String </: LegacyCovariant<Middle> -> String
|
|
||||||
checkSubtypeFailure(TYPE_REF<String Function(LegacyCovariant<Lower>)>(),
|
|
||||||
TYPE_REF<String Function(LegacyCovariant<Middle>)>());
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
// Copyright (c) 2019, 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=variance
|
|
||||||
|
|
||||||
// Tests the emission of explicit variance modifiers.
|
|
||||||
|
|
||||||
import 'dart:_foreign_helper' show TYPE_REF;
|
|
||||||
import 'dart:_runtime' show getGenericArgVariances, Variance;
|
|
||||||
|
|
||||||
import 'package:expect/expect.dart';
|
|
||||||
|
|
||||||
class A<in T> {}
|
|
||||||
|
|
||||||
class B<out T> {}
|
|
||||||
|
|
||||||
class C<inout T> {}
|
|
||||||
|
|
||||||
class D<T> {}
|
|
||||||
|
|
||||||
class E<inout X, out Y, in Z> {}
|
|
||||||
|
|
||||||
mixin F<in T> {}
|
|
||||||
|
|
||||||
class G<inout T> = Object with F<T>;
|
|
||||||
|
|
||||||
List? getVariances(Object type) {
|
|
||||||
// TODO(nshahan) Revisit when we decide if getGenericArgVariances will handle
|
|
||||||
// legacy and nullable wrappers.
|
|
||||||
return getGenericArgVariances(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
Expect.listEquals([Variance.contravariant], getVariances(TYPE_REF<A>())!);
|
|
||||||
|
|
||||||
Expect.listEquals([Variance.covariant], getVariances(TYPE_REF<B>())!);
|
|
||||||
|
|
||||||
Expect.listEquals([Variance.invariant], getVariances(TYPE_REF<C>())!);
|
|
||||||
|
|
||||||
// Implicit variance is not emitted into the generated code.
|
|
||||||
Expect.isNull(getVariances(TYPE_REF<D>()));
|
|
||||||
|
|
||||||
Expect.listEquals(
|
|
||||||
[Variance.invariant, Variance.covariant, Variance.contravariant],
|
|
||||||
getVariances(TYPE_REF<E>())!);
|
|
||||||
|
|
||||||
Expect.listEquals([Variance.contravariant], getVariances(TYPE_REF<F>())!);
|
|
||||||
|
|
||||||
Expect.listEquals([Variance.invariant], getVariances(TYPE_REF<G>())!);
|
|
||||||
}
|
|
|
@ -95,8 +95,22 @@ main() {
|
||||||
iterableLower = listMiddle;
|
iterableLower = listMiddle;
|
||||||
|
|
||||||
testCall(listMiddle);
|
testCall(listMiddle);
|
||||||
|
Expect.subtype<List<Contravariant<Middle>>, Iterable<Contravariant<Lower>>>();
|
||||||
|
Expect.notSubtype<Iterable<Contravariant<Lower>>,
|
||||||
|
List<Contravariant<Middle>>>();
|
||||||
|
Expect.notSubtype<List<Contravariant<Lower>>,
|
||||||
|
Iterable<Contravariant<Middle>>>();
|
||||||
|
|
||||||
Expect.subtype<Contravariant<Upper>, Contravariant<Middle>>();
|
Expect.subtype<Contravariant<Upper>, Contravariant<Middle>>();
|
||||||
Expect.subtype<Contravariant<Middle>, Contravariant<Middle>>();
|
Expect.subtype<Contravariant<Middle>, Contravariant<Middle>>();
|
||||||
Expect.notSubtype<Contravariant<Lower>, Contravariant<Middle>>();
|
Expect.notSubtype<Contravariant<Lower>, Contravariant<Middle>>();
|
||||||
|
|
||||||
|
Expect.subtype<Contravariant<Upper> Function(String),
|
||||||
|
Contravariant<Middle> Function(String)>();
|
||||||
|
Expect.notSubtype<Contravariant<Middle> Function(String),
|
||||||
|
Contravariant<Upper> Function(String)>();
|
||||||
|
Expect.subtype<String Function(Contravariant<Lower>),
|
||||||
|
String Function(Contravariant<Middle>)>();
|
||||||
|
Expect.notSubtype<String Function(Contravariant<Middle>),
|
||||||
|
String Function(Contravariant<Lower>)>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,10 @@ main() {
|
||||||
iterableMiddle = listMiddle;
|
iterableMiddle = listMiddle;
|
||||||
|
|
||||||
testCall(listMiddle);
|
testCall(listMiddle);
|
||||||
|
Expect.subtype<List<Invariant<Middle>>, Iterable<Invariant<Middle>>>();
|
||||||
|
Expect.notSubtype<Iterable<Invariant<Middle>>, List<Invariant<Middle>>>();
|
||||||
|
Expect.notSubtype<List<Invariant<Upper>>, Iterable<Invariant<Middle>>>();
|
||||||
|
Expect.notSubtype<List<Invariant<Lower>>, Iterable<Invariant<Middle>>>();
|
||||||
|
|
||||||
Expect.subtype<Invariant<Middle>, Invariant<Middle>>();
|
Expect.subtype<Invariant<Middle>, Invariant<Middle>>();
|
||||||
Expect.notSubtype<Invariant<Lower>, Invariant<Middle>>();
|
Expect.notSubtype<Invariant<Lower>, Invariant<Middle>>();
|
||||||
|
@ -167,4 +171,20 @@ main() {
|
||||||
|
|
||||||
Expect.subtype<Invariant<FutureOr<Never>>, Invariant<Future<Never>>>();
|
Expect.subtype<Invariant<FutureOr<Never>>, Invariant<Future<Never>>>();
|
||||||
Expect.subtype<Invariant<Future<Never>>, Invariant<FutureOr<Never>>>();
|
Expect.subtype<Invariant<Future<Never>>, Invariant<FutureOr<Never>>>();
|
||||||
|
|
||||||
|
Expect.subtype<Invariant<FutureOr<Null>>, Invariant<Future<Null>?>>();
|
||||||
|
Expect.subtype<Invariant<Future<Null>?>, Invariant<FutureOr<Null>>>();
|
||||||
|
|
||||||
|
Expect.subtype<String Function(Invariant<Middle>),
|
||||||
|
String Function(Invariant<Middle>)>();
|
||||||
|
Expect.subtype<Invariant<Middle> Function(String),
|
||||||
|
Invariant<Middle> Function(String)>();
|
||||||
|
Expect.notSubtype<Invariant<Upper> Function(String),
|
||||||
|
Invariant<Middle> Function(String)>();
|
||||||
|
Expect.notSubtype<String Function(Invariant<Upper>),
|
||||||
|
String Function(Invariant<Middle>)>();
|
||||||
|
Expect.notSubtype<Invariant<Lower> Function(String),
|
||||||
|
Invariant<Middle> Function(String)>();
|
||||||
|
Expect.notSubtype<String Function(Invariant<Lower>),
|
||||||
|
String Function(Invariant<Middle>)>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,8 +95,22 @@ main() {
|
||||||
iterableMiddle = listLower;
|
iterableMiddle = listLower;
|
||||||
|
|
||||||
testCall(listLower);
|
testCall(listLower);
|
||||||
|
Expect.subtype<List<Covariant<Lower>>, Iterable<Covariant<Middle>>>();
|
||||||
|
Expect.notSubtype<Iterable<Covariant<Middle>>, List<Covariant<Lower>>>();
|
||||||
|
Expect.notSubtype<List<Covariant<Upper>>, Iterable<Covariant<Middle>>>();
|
||||||
|
|
||||||
Expect.subtype<Covariant<Lower>, Covariant<Middle>>();
|
Expect.subtype<Covariant<Lower>, Covariant<Middle>>();
|
||||||
Expect.subtype<Covariant<Middle>, Covariant<Middle>>();
|
Expect.subtype<Covariant<Middle>, Covariant<Middle>>();
|
||||||
Expect.notSubtype<Covariant<Upper>, Covariant<Middle>>();
|
Expect.notSubtype<Covariant<Upper>, Covariant<Middle>>();
|
||||||
|
|
||||||
|
Expect.subtype<Covariant<Lower> Function(String),
|
||||||
|
Covariant<Middle> Function(String)>();
|
||||||
|
Expect.notSubtype<Covariant<Middle> Function(String),
|
||||||
|
Covariant<Lower> Function(String)>();
|
||||||
|
Expect.subtype<String Function(Covariant<Upper>),
|
||||||
|
String Function(Covariant<Middle>)>();
|
||||||
|
Expect.notSubtype<String Function(Covariant<Middle>),
|
||||||
|
String Function(Covariant<Upper>)>();
|
||||||
|
Expect.notSubtype<Covariant<Upper> Function(String),
|
||||||
|
Covariant<Middle> Function(String)>();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue