blob: 673ab1d49c274e728049496ecb680e905c956d8e [file] [log] [blame]
 /* * Copyright (c) 2018, 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. */ /** * @assertion A type T0 is a subtype of a type T1 (written T0 <: T1) when: * Named Function Types: T0 is U0 Function * (T0 x0, ..., Tn xn, {Tn+1 xn+1, ..., Tm xm}) * * and T1 is U1 Function(S0 y0, ..., Sn yn, * {Sn+1 yn+1, ..., Sq yq}) * and {yn+1, ... , yq} subsetof {xn+1, ... , xm} * and Si[Z0/Y0, ..., Zk/Yk] <: Vi[Z0/X0, ..., Zk/Xk] for i in 0...n * and Si[Z0/Y0, ..., Zk/Yk] <: Tj[Z0/X0, ..., Zk/Xk] for i in n+1...q, yj = xi * and U0[Z0/X0, ..., Zk/Xk] <: U1[Z0/Y0, ..., Zk/Yk] * and B0i[Z0/X0, ..., Zk/Xk] === B1i[Z0/Y0, ..., Zk/Yk] for i in 0...k * where the Zi are fresh type variables with bounds B0i[Z0/X0, ..., Zk/Xk] * @description Check that if there is i in n+1...q such that * Si[Z0/Y0, ..., Zk/Yk] is not subtype of Tj[Z0/X0, ..., Zk/Xk], then T0 is not * a subtype of T1. Test generic types * @author sgrekhov@unipro.ru */ /** * @description Check that if type T0 not a subtype of a type T1, then it cannot * be used as a class member of type T1 * @author sgrekhov@unipro.ru */ /* * This test is generated from named_function_types_fail_A32.dart and * class_member_fail_x01.dart. * Don't modify it. If you want to change this file, change one of the files * above and then run generator.dart to regenerate the tests. */ import '../../utils/common.dart'; import '../../../../Utils/expect.dart'; // SharedOptions=--enable-experiment=non-nullable class A {} class C extends A {} class U0 extends U1 {} class U1 {} class B0 {} class B1 {} class V0 {} class V1 {} class V2 {} class V3 {} class V4 {} class S0 extends V0 {} class S1 extends V1 {} class S2 extends V2 {} class S3 extends V3 {} class X0 extends B0 {} class X1 extends B1 {} class Y0 extends B0 {} class Y1 extends B1 {} typedef T0 = U0, int> Function( V0 x0, V1 x1, {V2? x2, V3? x3, V4? x4}); // S2, int> is not a subtype of V2 typedef T1 = U1 Function( S0, int> y0, S1, int> y1, {S2, int>? x2, S3, int>? x3}); U0, int> t0Func( V0 x0, V1 x1, {V2? x2, V3? x3, V4? x4}) => new U0, int>(); U1 t1Func( S0, int> y0, S1, int> y1, {S2, int>? x2, S3, int>? x3}) => new U1(); T0 t0Instance = t0Func; T1 t1Instance = t1Func; const t1Default = t1Func; class ClassMemberTestStatic { static T1 s = t1Default; ClassMemberTestStatic(dynamic val) { s = val; } static staticTest() { s = forgetType(t0Instance); } static set staticSetter(dynamic val) { s = val; } static T1 get staticGetter => forgetType(t0Instance); } class ClassMemberTestPublic { T1 m = t1Default; ClassMemberTestPublic(dynamic val) { m = val; } ClassMemberTestPublic.short(this.m); ClassMemberTestPublic.validConstructor() {} test(dynamic val) { m = val; } set setter(dynamic val) { m = val; } T1 get getter => forgetType(t0Instance); } class ClassMemberTestPrivate { T1 _m = t1Default; ClassMemberTestPrivate(dynamic val) { _m = val; } ClassMemberTestPrivate.short(this._m); ClassMemberTestPrivate.validConstructor() {} test(dynamic val) { _m = val; } set setter(dynamic val) { _m = val; } } class ClassMemberTestInitFail { static T1 s = forgetType(t0Instance); T1 m = forgetType(t0Instance); } class ClassMemberTestGenericPublic { X m; ClassMemberTestGenericPublic(dynamic val): m = val { } ClassMemberTestGenericPublic.short(this.m); test(dynamic val) { m = val; } set setter(dynamic val) { m = val; } X get getter => forgetType(t0Instance); } class ClassMemberTestGenericPrivate { X _m; ClassMemberTestGenericPrivate(dynamic val): _m = val { } ClassMemberTestGenericPrivate.short(this._m); test(dynamic val) { _m = val; } set setter(dynamic val) { _m = val; } } main() { // Test initialization Expect.throws(() {ClassMemberTestInitFail.s;}, (e) => e is TypeError); Expect.throws(() {new ClassMemberTestInitFail();}, (e) => e is TypeError); // Test constructors Expect.throws(() { new ClassMemberTestPublic(t0Instance); }, (e) => e is TypeError); Expect.throws(() { new ClassMemberTestPublic.short(forgetType(t0Instance)); }, (e) => e is TypeError); Expect.throws(() { new ClassMemberTestPrivate(t0Instance); }, (e) => e is TypeError); Expect.throws(() { new ClassMemberTestPrivate.short(forgetType(t0Instance)); }, (e) => e is TypeError); // Test class variables Expect.throws(() { new ClassMemberTestPublic(t1Instance).m = forgetType(t0Instance); }, (e) => e is TypeError); // Test setters Expect.throws(() { new ClassMemberTestPublic(t1Instance).setter = t0Instance; }, (e) => e is TypeError); Expect.throws(() { new ClassMemberTestPrivate(t1Instance).setter = t0Instance; }, (e) => e is TypeError); // Test methods Expect.throws(() { new ClassMemberTestPublic(t1Instance).test(t0Instance); }, (e) => e is TypeError); Expect.throws(() { new ClassMemberTestPrivate(t1Instance).test(t0Instance); }, (e) => e is TypeError); // Test getters Expect.throws(() { new ClassMemberTestPublic(t1Instance).getter; }, (e) => e is TypeError); // Test static stuff Expect.throws(() { new ClassMemberTestStatic(t0Instance); }, (e) => e is TypeError); Expect.throws(() { ClassMemberTestStatic.staticSetter = t0Instance; }, (e) => e is TypeError); Expect.throws(() { ClassMemberTestStatic.staticGetter; }, (e) => e is TypeError); Expect.throws(() { ClassMemberTestStatic.staticTest(); }, (e) => e is TypeError); // Test type parameters }