Skip to content

Commit d26afe8

Browse files
committed
dart-lang#1399. [Records] Subtyping tests for records added (dart-lang#1412)
Authored by @sgrekhov. Subtyping tests for records added.
1 parent 5b6211c commit d26afe8

File tree

190 files changed

+23169
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+23169
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
/// @author [email protected]
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+
/// @author [email protected]
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+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
/// @author [email protected]
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. Test superclass members
18+
/// @author [email protected]
19+
///
20+
/// This test is generated from records_A01.dart and
21+
/// arguments_binding_x02.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+
38+
class ArgumentsBindingSuper1_t02 {
39+
(num, num, String?) m;
40+
41+
ArgumentsBindingSuper1_t02((num, num, String?) value): m = value {}
42+
ArgumentsBindingSuper1_t02.named((num, num, String?) value, {(num, num, String?) val2 = t1Default}): m = value {}
43+
ArgumentsBindingSuper1_t02.positional((num, num, String?) value, [(num, num, String?) val2 = t1Default]): m = value {}
44+
ArgumentsBindingSuper1_t02.short(this.m);
45+
46+
void superTest((num, num, String?) val) {}
47+
void superTestPositioned((num, num, String?) val, [(num, num, String?) val2 = t1Default]) {}
48+
void superTestNamed((num, num, String?) val, {(num, num, String?) val2 = t1Default}) {}
49+
(num, num, String?) get superGetter => m;
50+
void set superSetter((num, num, String?) val) {}
51+
}
52+
53+
class ArgumentsBinding1_t02 extends ArgumentsBindingSuper1_t02 {
54+
ArgumentsBinding1_t02(dynamic t1) : super(t1) {}
55+
ArgumentsBinding1_t02.c2(dynamic t1, dynamic t2) : super.named(t1, val2: t2) {}
56+
ArgumentsBinding1_t02.c3(dynamic t1) : super.positional(t1) {}
57+
ArgumentsBinding1_t02.c4(dynamic t1, dynamic t2) : super.positional(t1, t2) {}
58+
ArgumentsBinding1_t02.c5(dynamic t1) : super.short(t1) {}
59+
60+
test(dynamic t1, dynamic t2) {
61+
superTest(t1);
62+
superTestPositioned(t1);
63+
superTestPositioned(t2, t1);
64+
superTestNamed(t1);
65+
superTestNamed(t2, val2: t1);
66+
superSetter = t1;
67+
m = t1;
68+
superGetter;
69+
}
70+
}
71+
72+
class ArgumentsBindingSuper2_t02<X> {
73+
X m;
74+
75+
ArgumentsBindingSuper2_t02(X value): m = value {}
76+
ArgumentsBindingSuper2_t02.named(X value, {required X val2}):m = value {}
77+
ArgumentsBindingSuper2_t02.short(this.m);
78+
79+
void superTest(X val) {}
80+
void superTestNamed(X val, {required X val2}) {}
81+
X get superGetter => m;
82+
void set superSetter(X val) {}
83+
}
84+
85+
class ArgumentsBinding2_t02<X> extends ArgumentsBindingSuper2_t02<X> {
86+
ArgumentsBinding2_t02(X t1) : super(t1) {}
87+
ArgumentsBinding2_t02.c2(dynamic t1, dynamic t2) : super.named(t1, val2: t2) {}
88+
ArgumentsBinding2_t02.c5(dynamic t1) : super.short(t1) {}
89+
90+
test(X t1, X t2) {
91+
superTest(t1);
92+
superTestNamed(t2, val2: t1);
93+
superSetter = t1;
94+
m = t1;
95+
superGetter;
96+
}
97+
}
98+
99+
main() {
100+
ArgumentsBinding1_t02 c1 = new ArgumentsBinding1_t02(forgetType(t0Instance));
101+
c1 = new ArgumentsBinding1_t02.c2(t1Instance, forgetType(t0Instance));
102+
c1 = new ArgumentsBinding1_t02.c3(forgetType(t0Instance));
103+
c1 = new ArgumentsBinding1_t02.c4(t1Instance, forgetType(t0Instance));
104+
c1 = new ArgumentsBinding1_t02.c5(forgetType(t0Instance));
105+
106+
c1.test(forgetType(t0Instance), t1Instance);
107+
c1.superTest(forgetType(t0Instance));
108+
c1.superTestPositioned(forgetType(t0Instance));
109+
c1.superTestPositioned(t1Instance, forgetType(t0Instance));
110+
c1.superTestNamed(forgetType(t0Instance));
111+
c1.superTestNamed(t1Instance, val2: forgetType(t0Instance));
112+
c1.superSetter = forgetType(t0Instance);
113+
c1.superGetter;
114+
115+
// Test type parameters
116+
117+
//# <-- NotGenericFunctionType
118+
ArgumentsBinding2_t02<(num, num, String?)> c2 =
119+
new ArgumentsBinding2_t02<(num, num, String?)>(forgetType(t0Instance));
120+
c2 = new ArgumentsBinding2_t02<(num, num, String?)>.c2(t1Instance, forgetType(t0Instance));
121+
c2 = new ArgumentsBinding2_t02<(num, num, String?)>.c5(forgetType(t0Instance));
122+
123+
c2.test(forgetType(t0Instance), t1Instance);
124+
c2.superTest(forgetType(t0Instance));
125+
c2.superTestNamed(t1Instance, val2: forgetType(t0Instance));
126+
c2.superSetter = forgetType(t0Instance);
127+
c2.superGetter;
128+
//# -->
129+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
/// @author [email protected]
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. Test mixin members
18+
/// @author [email protected]
19+
///
20+
/// This test is generated from records_A01.dart and
21+
/// arguments_binding_x03.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+
38+
class ArgumentsBindingMixin1_t03 {
39+
(num, num, String?) m = t1Default;
40+
41+
void superTest((num, num, String?) val) {}
42+
void superTestPositioned((num, num, String?) val, [(num, num, String?) val2 = t1Default]) {}
43+
void superTestNamed((num, num, String?) val, {(num, num, String?) val2 = t1Default}) {}
44+
(num, num, String?) get superGetter => m;
45+
void set superSetter((num, num, String?) val) {}
46+
}
47+
48+
class ArgumentsBinding1_t03 extends Object with ArgumentsBindingMixin1_t03 {
49+
50+
test(dynamic t1, dynamic t2) {
51+
superTest(t1);
52+
superTestPositioned(t1);
53+
superTestPositioned(t2, t1);
54+
superTestNamed(t1);
55+
superTestNamed(t2, val2: t1);
56+
superSetter = t1;
57+
m = t1;
58+
superGetter;
59+
}
60+
}
61+
62+
class ArgumentsBindingMixin2_t03<X> {
63+
void superTest(X val) {}
64+
void superTestNamed(X val, {required X val2}) {}
65+
void set superSetter(X val) {}
66+
}
67+
68+
class ArgumentsBinding2_t03<X> extends Object with ArgumentsBindingMixin2_t03<X> {
69+
70+
test(dynamic t1, dynamic t2) {
71+
superTest(t1);
72+
superTestNamed(t2, val2: t1);
73+
superSetter = t1;
74+
}
75+
}
76+
77+
main() {
78+
ArgumentsBinding1_t03 c1 = new ArgumentsBinding1_t03();
79+
80+
c1.test(forgetType(t0Instance), t1Instance);
81+
c1.superTest(forgetType(t0Instance));
82+
c1.superTestPositioned(forgetType(t0Instance));
83+
c1.superTestPositioned(t1Instance, forgetType(t0Instance));
84+
c1.superTestNamed(forgetType(t0Instance));
85+
c1.superTestNamed(t1Instance, val2: forgetType(t0Instance));
86+
c1.superSetter = forgetType(t0Instance);
87+
c1.superGetter;
88+
89+
// Test type parameters
90+
91+
//# <-- NotGenericFunctionType
92+
ArgumentsBinding2_t03<(num, num, String?)> c2 = new ArgumentsBinding2_t03<(num, num, String?)>();
93+
c2.test(forgetType(t0Instance), t1Instance);
94+
c2.superTest(forgetType(t0Instance));
95+
c2.superTestNamed(t1Instance, val2: forgetType(t0Instance));
96+
c2.superSetter = forgetType(t0Instance);
97+
//# -->
98+
}

0 commit comments

Comments
 (0)