@@ -756,6 +756,49 @@ class ConstraintMatchingTest extends AbstractTypeSystemTest {
756756 covariant : true );
757757 }
758758
759+ void test_variance_contravariant () {
760+ // class A<in T>
761+ var tContravariant = typeParameter ('T' , variance: Variance .contravariant);
762+ var tType = typeParameterType (tContravariant);
763+ var A = class_ (name: 'A' , typeParameters: [tContravariant]);
764+
765+ // A<num>
766+ // A<T>
767+ var aNum = interfaceTypeStar (A , typeArguments: [numType]);
768+ var aT = interfaceTypeStar (A , typeArguments: [tType]);
769+
770+ _checkIsSubtypeMatchOf (aT, aNum, [tType], ['num <: T' ], covariant : true );
771+ }
772+
773+ void test_variance_covariant () {
774+ // class A<out T>
775+ var tCovariant = typeParameter ('T' , variance: Variance .covariant );
776+ var tType = typeParameterType (tCovariant);
777+ var A = class_ (name: 'A' , typeParameters: [tCovariant]);
778+
779+ // A<num>
780+ // A<T>
781+ var aNum = interfaceTypeStar (A , typeArguments: [numType]);
782+ var aT = interfaceTypeStar (A , typeArguments: [tType]);
783+
784+ _checkIsSubtypeMatchOf (aT, aNum, [tType], ['T <: num' ], covariant : true );
785+ }
786+
787+ void test_variance_invariant () {
788+ // class A<inout T>
789+ var tInvariant = typeParameter ('T' , variance: Variance .invariant);
790+ var tType = typeParameterType (tInvariant);
791+ var A = class_ (name: 'A' , typeParameters: [tInvariant]);
792+
793+ // A<num>
794+ // A<T>
795+ var aNum = interfaceTypeStar (A , typeArguments: [numType]);
796+ var aT = interfaceTypeStar (A , typeArguments: [tType]);
797+
798+ _checkIsSubtypeMatchOf (aT, aNum, [tType], ['T <: num' , 'num <: T' ],
799+ covariant : true );
800+ }
801+
759802 void test_x_futureOr_fail_both_branches () {
760803 // List<T> <: FutureOr<String> can't be satisfied because neither
761804 // List<T> <: Future<String> nor List<T> <: int can be satisfied
@@ -821,49 +864,6 @@ class ConstraintMatchingTest extends AbstractTypeSystemTest {
821864 covariant : true );
822865 }
823866
824- void test_variance_covariant () {
825- // class A<out T>
826- var tCovariant = typeParameter ('T' , variance: Variance .covariant );
827- var tType = typeParameterType (tCovariant);
828- var A = class_ (name: 'A' , typeParameters: [tCovariant]);
829-
830- // A<num>
831- // A<T>
832- var aNum = interfaceType (A , typeArguments: [numType]);
833- var aT = interfaceType (A , typeArguments: [tType]);
834-
835- _checkIsSubtypeMatchOf (aT, aNum, [tType], ['T <: num' ], covariant : true );
836- }
837-
838- void test_variance_contravariant () {
839- // class A<in T>
840- var tContravariant = typeParameter ('T' , variance: Variance .contravariant);
841- var tType = typeParameterType (tContravariant);
842- var A = class_ (name: 'A' , typeParameters: [tContravariant]);
843-
844- // A<num>
845- // A<T>
846- var aNum = interfaceType (A , typeArguments: [numType]);
847- var aT = interfaceType (A , typeArguments: [tType]);
848-
849- _checkIsSubtypeMatchOf (aT, aNum, [tType], ['num <: T' ], covariant : true );
850- }
851-
852- void test_variance_invariant () {
853- // class A<inout T>
854- var tInvariant = typeParameter ('T' , variance: Variance .invariant);
855- var tType = typeParameterType (tInvariant);
856- var A = class_ (name: 'A' , typeParameters: [tInvariant]);
857-
858- // A<num>
859- // A<T>
860- var aNum = interfaceType (A , typeArguments: [numType]);
861- var aT = interfaceType (A , typeArguments: [tType]);
862-
863- _checkIsSubtypeMatchOf (aT, aNum, [tType], ['T <: num' , 'num <: T' ],
864- covariant : true );
865- }
866-
867867 void _checkIsNotSubtypeMatchOf (
868868 DartType t1, DartType t2, Iterable <TypeParameterType > typeFormals,
869869 {bool covariant }) {
@@ -3226,103 +3226,6 @@ class LeastUpperBoundTest extends BoundTestBase {
32263226 }
32273227}
32283228
3229- //class Mix with ElementsTypesMixin {
3230- // TypeProvider typeProvider;
3231- // Dart2TypeSystem typeSystem;
3232- //
3233- // FeatureSet get testFeatureSet {
3234- // return FeatureSet.forTesting();
3235- // }
3236- //
3237- // void setUp() {
3238- // var analysisContext = TestAnalysisContext(
3239- // featureSet: testFeatureSet,
3240- // );
3241- // typeProvider = analysisContext.typeProvider;
3242- // typeSystem = analysisContext.typeSystem;
3243- // }
3244- //}
3245-
3246- class SubtypingTestBase extends AbstractTypeSystemTest {
3247- void _checkEquivalent (DartType type1, DartType type2) {
3248- _checkIsSubtypeOf (type1, type2);
3249- _checkIsSubtypeOf (type2, type1);
3250- }
3251-
3252- void _checkGroups (DartType t1,
3253- {List <DartType > equivalents,
3254- List <DartType > unrelated,
3255- List <DartType > subtypes,
3256- List <DartType > supertypes}) {
3257- if (equivalents != null ) {
3258- for (DartType t2 in equivalents) {
3259- _checkEquivalent (t1, t2);
3260- }
3261- }
3262- if (unrelated != null ) {
3263- for (DartType t2 in unrelated) {
3264- _checkUnrelated (t1, t2);
3265- }
3266- }
3267- if (subtypes != null ) {
3268- for (DartType t2 in subtypes) {
3269- _checkIsStrictSubtypeOf (t2, t1);
3270- }
3271- }
3272- if (supertypes != null ) {
3273- for (DartType t2 in supertypes) {
3274- _checkIsStrictSubtypeOf (t1, t2);
3275- }
3276- }
3277- }
3278-
3279- void _checkIsNotSubtypeOf (DartType type1, DartType type2) {
3280- var strType1 = _toStringWithNullability (type1);
3281- var strType2 = _toStringWithNullability (type2);
3282- expect (typeSystem.isSubtypeOf (type1, type2), false ,
3283- reason: '$strType1 was not supposed to be a subtype of $strType2 ' );
3284- }
3285-
3286- void _checkIsStrictSubtypeOf (DartType type1, DartType type2) {
3287- _checkIsSubtypeOf (type1, type2);
3288- _checkIsNotSubtypeOf (type2, type1);
3289- }
3290-
3291- void _checkIsSubtypeOf (DartType type1, DartType type2) {
3292- expect (typeSystem.isSubtypeOf (type1, type2), true ,
3293- reason: '$type1 is not a subtype of $type2 ' );
3294- }
3295-
3296- void _checkLattice (
3297- DartType top, DartType left, DartType right, DartType bottom) {
3298- _checkGroups (top,
3299- equivalents: < DartType > [top],
3300- subtypes: < DartType > [left, right, bottom]);
3301- _checkGroups (left,
3302- equivalents: < DartType > [left],
3303- subtypes: < DartType > [bottom],
3304- unrelated: < DartType > [right],
3305- supertypes: < DartType > [top]);
3306- _checkGroups (right,
3307- equivalents: < DartType > [right],
3308- subtypes: < DartType > [bottom],
3309- unrelated: < DartType > [left],
3310- supertypes: < DartType > [top]);
3311- _checkGroups (bottom,
3312- equivalents: < DartType > [bottom],
3313- supertypes: < DartType > [top, left, right]);
3314- }
3315-
3316- void _checkUnrelated (DartType type1, DartType type2) {
3317- _checkIsNotSubtypeOf (type1, type2);
3318- _checkIsNotSubtypeOf (type2, type1);
3319- }
3320-
3321- static String _toStringWithNullability (DartType type) {
3322- return (type as TypeImpl ).toString (withNullability: true );
3323- }
3324- }
3325-
33263229@reflectiveTest
33273230class TypeSystemTest extends AbstractTypeSystemTest {
33283231 InterfaceTypeImpl get functionClassTypeNone {
0 commit comments