// 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. // @dart=2.9 // Testing that i2b and checks for correct super-boundedness are applied // to type arguments, taking the variance of type parameters into account. // Standard type comparison support. typedef F = void Function(); F toF(X x) => null; // Material specific to this test. typedef Fcov = X Function(); typedef Fcon = Function(X); typedef Finv = X Function(X); class Acov, Y> {} class Acon, Y> {} class Ainv, Y> {} typedef FcovBound = X Function(); typedef FconBound = Function(X); typedef FinvBound = X Function(X); class AcovBound, Y extends num> {} class AconBound, Y extends num> {} class AinvBound, Y extends num> {} class A {} typedef FcovCyclicBound> = X Function(); typedef FconCyclicBound> = Function(X); typedef FinvCyclicBound> = X Function(X); class AcovCyclicBound, Y extends A> {} class AconCyclicBound, Y extends A> {} class AinvCyclicBound, Y extends A> {} typedef FcovCyclicCoBound = X Function(); typedef FconCyclicCoBound = Function(X); typedef FinvCyclicCoBound = X Function(X); class AcovCyclicCoBound, Y extends Function(Y)> { } class AconCyclicCoBound, Y extends Function(Y)> { } class AinvCyclicCoBound, Y extends Function(Y)> { } class B {} void testTypeAliasAsTypeArgument() { // I2b: Use bounds (Fcov, dynamic), then replace covariant occurrence // (of `Y` in `Acov, _>`) by `Y`s value `dynamic`. Resulting type // `Acov, dynamic>` is regular-bounded. Acov source1; var fsource1 = toF(source1); F, dynamic>> target1 = fsource1; // I2b: Use bounds (Fcon, dynamic), then replace contravariant occurrence // (of `Y` in `Acon, _>`) by `Null`. Resulting type // is super-bounded: Acon, Null> is regular-bounded. Acon source2; var fsource2 = toF(source2); F, dynamic>> target2 = fsource2; // I2b: Use bounds (Finv, dynamic) then replace invariant occurrence // (of `Y` in `Ainv, _>`) by `Y`s value `dynamic`. Resulting type // `Ainv, dynamic>` is regular-bounded. Ainv source3; var fsource3 = toF(source3); F, dynamic>> target3 = fsource3; // I2b: Use bounds (FcovBound, num), then replace covariant occurrence // (of `Y` in `AcovBound, _>`) by `Y`s value `num`. // Resulting type `AcovBound, num>` is regular-bounded. AcovBound source4; var fsource4 = toF(source4); F, num>> target4 = fsource4; // I2b: Use bounds (FconBound, num), then replace contravariant occurrence // of `Y` in `AconBound, _>` by `Null`. Resulting type is // super-bounded: AconBound, num> is regular-bounded. AconBound source5; var fsource5 = toF(source5); F, num>> target5 = fsource5; // I2b: Use bounds (FinvBound, num), then replace invariant occurrence // of `Y` in `AinvBound, _>` by `Y`s value `num`. Resulting // type `AinvBound, num>` is regular-bounded. AinvBound source6; var fsource6 = toF(source6); F, num>> target6 = fsource6; // I2b: Use bounds (FcovCyclicBound, A), then break cycle {Y} by // replacing covariant occurrence of `Y` in `AcovCyclicBound<_, A>` // by `dynamic`; then replace covariant occurrence of `Y` in // `AcovCyclicBound, _>` by `Y`s value `A`. // Resulting type `AcovCyclicBound>, A>>` // is regular-bounded. AcovCyclicBound source7; var fsource7 = toF(source7); F>, A>> target7 = fsource7; // I2b: Use bounds (FconCyclicBound, A), then break cycle {Y} by // replacing covariant occurrence of `Y` in `AconCyclicBound<_, A>` // by `dynamic`; then replace contravariant occurrence of `Y` in // `AconCyclicBound, _>` by `Null`. // Resulting type `AconCyclicBound, A>>` is // super-bounded because `AconCyclicBound, A>>` // is regular-bounded. AconCyclicBound source8; var fsource8 = toF(source8); F, A>> target8 = fsource8; // I2b: Use bounds (FinvCyclicBound, A), then break cycle {Y} by // replacing covariant occurrence of `Y` in `AinvCyclicBound<_, A>` // by `dynamic`; then replace invariant occurrence of `Y` in // `AinvCyclicBound, _>` by `Y`s value `A`. // Resulting type `AinvCyclicBound>, A>>` // looks regular-bounded, but contains `FinvCyclicBound>` which // is not well-bounded. AinvCyclicBound source9; //# 01: compile-time error // var fsource9 = toF(source9); // F>, A>> target9 = // fsource9; // I2b: Use bounds (FcovCyclicCoBound, Function(Y)), then break cycle {Y} // by replacing contravariant occurrence of `Y` in // `AcovCyclicCoBound<_, Function(Y)>` by `Null`; then replace covariant // occurrence of `Y` in `AcovCyclicCoBound, _>` by `Y`s // value `Function(Null)`. Resulting type // `AcovCyclicCoBound, Function(Null)>` // is regular-bounded, with subterm `FcovCyclicCoBound` which // is super-bounded because `FcovCyclicCoBound` is // regular-bounded. AcovCyclicCoBound source10; var fsource10 = toF(source10); F, Function(Null)>> target10 = fsource10; // I2b: Use bounds (FconCyclicCoBound, Function(Y)), then break cycle {Y} // by replacing contravariant occurrence of `Y` in // `AconCyclicCoBound<_, Function(Y)>` by `Null`; then replace contravariant // occurrence of `Y` in `AconCyclicCoBound, _>` by // `Null`. Resulting type // `AconCyclicCoBound, Function(Null)>` is // super-bounded because // `AconCyclicCoBound, Function(Object)>` is // regular-bounded. AconCyclicCoBound source11; var fsource11 = toF(source11); F, Function(Null)>> target11 = fsource11; // I2b: Use bounds (FinvCyclicCoBound, Function(Y)), then break cycle {Y} // by replacing contravariant occurrence of `Y` in // `AinvCyclicCoBound<_, Function(Y)>` by `Null`; then replace invariant // occurrence of `Y` in `AinvCyclicCoBound, _>` by `Y`s // value `Function(Null)`. // Resulting type // `AinvCyclicCoBound, Function(Null)>>` // looks regular-bounded, but contains `FinvCyclicCoBound` // which is not well-bounded. AinvCyclicCoBound source12; //# 02: compile-time error // var fsource12 = toF(source12); // F, Function(Null)>> // target12 = fsource12; } void testNested() { // Everything gets the same treatment when the cases from `testTopLevel` // are duplicated at the nested level in a covariant position. B source1; var fsource1 = toF(source1); F, dynamic>>> target1 = fsource1; B source2; var fsource2 = toF(source2); F, dynamic>>> target2 = fsource2; B source3; var fsource3 = toF(source3); F, dynamic>>> target3 = fsource3; B source4; var fsource4 = toF(source4); F, num>>> target4 = fsource4; B source5; var fsource5 = toF(source5); F, num>>> target5 = fsource5; B source6; var fsource6 = toF(source6); F, num>>> target6 = fsource6; B source7; var fsource7 = toF(source7); F>, A>>> target7 = fsource7; B source8; var fsource8 = toF(source8); F, A>>> target8 = fsource8; B source9; //# 03: compile-time error // var fsource9 = toF(source9); // F>, A>>> target9 = // fsource9; B source10; var fsource10 = toF(source10); F, Function(Null)>>> target10 = fsource10; B source11; var fsource11 = toF(source11); F, Function(Null)>>> target11 = fsource11; B source12; //# 04: compile-time error // var fsource12 = toF(source12); // F, Function(Null)>>> // target12 = fsource12; } main() { testTypeAliasAsTypeArgument(); testNested(); }