|
| 1 | +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +/// @assertion We say that a type T0 is a subtype of a type T1 (written |
| 6 | +/// T0 <: T1) when: |
| 7 | +/// A record type A is a subtype of record type B iff they have same shape and |
| 8 | +/// the types of all fields of A are subtypes of the corresponding field types |
| 9 | +/// of B |
| 10 | +/// |
| 11 | +/// @description Check that if type T0 is a record with the same shape that T1 |
| 12 | +/// and the types of all fields of T0 is subtype of of the corresponding field |
| 13 | +/// types of T1 then T0 is subtype of T1. Check positional fields only |
| 14 | + |
| 15 | +/// |
| 16 | +/// @description Check that if type T0 is a subtype of a type T1, then instance |
| 17 | +/// of T0 can be used as an argument of type T1 |
| 18 | + |
| 19 | +/// |
| 20 | +/// This test is generated from records_A01.dart and |
| 21 | +/// arguments_binding_x01.dart. |
| 22 | +/// Don't modify it. If you want to change this test, change one of the files |
| 23 | +/// above and then run generator.dart to regenerate the tests. |
| 24 | +
|
| 25 | + |
| 26 | +import '../../utils/common.dart'; |
| 27 | + |
| 28 | +// SharedOptions=--enable-experiment=records |
| 29 | + |
| 30 | +(int x, double y, String) t0Instance = (42, 3.14, ""); |
| 31 | +(num, num z, String?) t1Instance = (0, 0, null); |
| 32 | + |
| 33 | +const t1Default = (0, 0, null); |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +namedArgumentsFunc1((num, num, String?) t1, {(num, num, String?) t2 = t1Default}) {} |
| 38 | +positionalArgumentsFunc1((num, num, String?) t1, [(num, num, String?) t2 = t1Default]) {} |
| 39 | + |
| 40 | +namedArgumentsFunc2<X>(X t1, {required X t2}) {} |
| 41 | + |
| 42 | +class ArgumentsBindingClass { |
| 43 | + ArgumentsBindingClass((num, num, String?) t1) {} |
| 44 | + |
| 45 | + ArgumentsBindingClass.named((num, num, String?) t1, {(num, num, String?) t2 = t1Default}) {} |
| 46 | + ArgumentsBindingClass.positional((num, num, String?) t1, [(num, num, String?) t2 = t1Default]) {} |
| 47 | + |
| 48 | + factory ArgumentsBindingClass.fNamed((num, num, String?) t1, {(num, num, String?) t2 = t1Default}) { |
| 49 | + return new ArgumentsBindingClass.named(t1, t2: t2); |
| 50 | + } |
| 51 | + factory ArgumentsBindingClass.fPositional((num, num, String?) t1, [(num, num, String?) t2 = t1Default]) { |
| 52 | + return new ArgumentsBindingClass.positional(t1, t2); |
| 53 | + } |
| 54 | + |
| 55 | + static namedArgumentsStaticMethod((num, num, String?) t1, {(num, num, String?) t2 = t1Default}) {} |
| 56 | + static positionalArgumentsStaticMethod((num, num, String?) t1, [(num, num, String?) t2 = t1Default]) {} |
| 57 | + |
| 58 | + namedArgumentsMethod((num, num, String?) t1, {(num, num, String?) t2 = t1Default}) {} |
| 59 | + positionalArgumentsMethod((num, num, String?) t1, [(num, num, String?) t2 = t1Default]) {} |
| 60 | + |
| 61 | + set testSetter((num, num, String?) val) {} |
| 62 | +} |
| 63 | + |
| 64 | +class ArgumentsBindingGen<X> { |
| 65 | + ArgumentsBindingGen(X t1) {} |
| 66 | + |
| 67 | + ArgumentsBindingGen.named(X t1, {required X t2}) {} |
| 68 | + |
| 69 | + factory ArgumentsBindingGen.fNamed(X t1, {required X t2}) { |
| 70 | + return new ArgumentsBindingGen.named(t1, t2: t2); |
| 71 | + } |
| 72 | + |
| 73 | + namedArgumentsMethod(X t1, {required X t2}) {} |
| 74 | + |
| 75 | + set testSetter(X val) {} |
| 76 | +} |
| 77 | + |
| 78 | +main() { |
| 79 | + // test functions |
| 80 | + namedArgumentsFunc1(forgetType(t0Instance), t2: forgetType(t0Instance)); |
| 81 | + positionalArgumentsFunc1(forgetType(t0Instance), forgetType(t0Instance)); |
| 82 | + |
| 83 | + // test class constructors |
| 84 | + ArgumentsBindingClass instance1 = |
| 85 | + new ArgumentsBindingClass(forgetType(t0Instance)); |
| 86 | + instance1 = new ArgumentsBindingClass.fNamed(forgetType(t0Instance), |
| 87 | + t2: forgetType(t0Instance)); |
| 88 | + instance1 = new ArgumentsBindingClass.named(forgetType(t0Instance), |
| 89 | + t2: forgetType(t0Instance)); |
| 90 | + instance1 = new ArgumentsBindingClass.positional(forgetType(t0Instance), |
| 91 | + forgetType(t0Instance)); |
| 92 | + |
| 93 | + // tests methods and setters |
| 94 | + instance1.namedArgumentsMethod(forgetType(t0Instance), |
| 95 | + t2: forgetType(t0Instance)); |
| 96 | + instance1.positionalArgumentsMethod(forgetType(t0Instance), |
| 97 | + forgetType(t0Instance)); |
| 98 | + instance1.testSetter = forgetType(t0Instance); |
| 99 | + |
| 100 | + // test static methods |
| 101 | + ArgumentsBindingClass.namedArgumentsStaticMethod(forgetType(t0Instance), |
| 102 | + t2: forgetType(t0Instance)); |
| 103 | + ArgumentsBindingClass.positionalArgumentsStaticMethod( |
| 104 | + forgetType(t0Instance), forgetType(t0Instance)); |
| 105 | + |
| 106 | + // Test type parameters |
| 107 | + |
| 108 | + //# <-- NotGenericFunctionType |
| 109 | + // test generic functions |
| 110 | + namedArgumentsFunc2<(num, num, String?)>(forgetType(t0Instance), t2: forgetType(t0Instance)); |
| 111 | + |
| 112 | + // test generic class constructors |
| 113 | + ArgumentsBindingGen<(num, num, String?)> instance2 = |
| 114 | + new ArgumentsBindingGen<(num, num, String?)>(forgetType(t0Instance)); |
| 115 | + instance2 = new ArgumentsBindingGen<(num, num, String?)>.fNamed(forgetType(t0Instance), |
| 116 | + t2: forgetType(t0Instance)); |
| 117 | + instance2 = new ArgumentsBindingGen<(num, num, String?)>.named(forgetType(t0Instance), |
| 118 | + t2: forgetType(t0Instance)); |
| 119 | + |
| 120 | + // test generic class methods and setters |
| 121 | + instance2.namedArgumentsMethod(forgetType(t0Instance), |
| 122 | + t2: forgetType(t0Instance)); |
| 123 | + instance2.testSetter = forgetType(t0Instance); |
| 124 | + //# --> |
| 125 | +} |
0 commit comments