44
55import "package:expect/expect.dart" ;
66
7- // Tests that const/new-insertion does the right thing for
8- // composite object creations.
9- //
10- // The right thing is that map and list literals are only constant
11- // if in a constant context.
12- // Object creation is const if constructor is const and all arguments are const.
7+ // Tests that new-insertion always inserts `new` when not in const context,
8+ // no matter what the arguments are.
9+ // There is (currently) no automatic const insertion in non-const context.
1310//
1411// Not testing inference, so all type arguments are explicit.
1512
@@ -34,27 +31,22 @@ main() {
3431 var cd5 = C (d42); // Non-constant context, so `new`.
3532
3633 Expect .identical (cd1, cd2);
37- Expect .allDistinct ([cd1, cd3]);
38- Expect .allDistinct ([cd1, cd4, cd5]);
34+ Expect .allDistinct ([cd1, cd3, cd4, cd5]);
3935 }
4036
4137 {
4238 // List inside other constructor
4339 const cl1 = const C (const < int > [37 ]);
4440 const cl2 = C (clist); // Constant context.
4541 const cl3 = C (const < int > [37 ]); // Constant context.
46- const cl4 = C (< int > [37 ]);
42+ const cl4 = C (< int > [37 ]); // Constant context.
4743 var cl5 = C (clist); // Non-constant context, so `new`.
4844 var cl6 = C (const < int > [37 ]); // Non-constant context, so `new`.
4945 var cl7 = C (list); // Non-constant context, so `new`.
5046 var cl8 = C (< int > [37 ]); // Non-constant context, so `new`.
5147
52- Expect .identical (cl1, cl2);
53- Expect .identical (cl1, cl3);
54- Expect .identical (cl1, cl4);
55- Expect .allDistinct ([cl1, cl5]);
56- Expect .allDistinct ([cl1, cl6]);
57- Expect .allDistinct ([cl1, cl7, cl8]);
48+ Expect .allIdentical ([cl1, cl2, cl3, cl4]);
49+ Expect .allDistinct ([cl1, cl5, cl6, cl7, cl8]);
5850 }
5951
6052 {
@@ -69,9 +61,7 @@ main() {
6961
7062 Expect .identical (cm1, cm2);
7163 Expect .identical (cm1, cm3);
72- Expect .allDistinct ([cm1, cm4]);
73- Expect .allDistinct ([cm1, cm5]);
74- Expect .allDistinct ([cm1, cm6, cm7]);
64+ Expect .allDistinct ([cm1, cm4, cm5, cm6, cm7]);
7565 }
7666
7767 {
@@ -93,22 +83,14 @@ main() {
9383
9484 Expect .identical (n1, n2);
9585 Expect .identical (n1, n3);
96- Expect .allDistinct ([n1, n4]);
97- Expect .allDistinct ([n1, n8]);
98- Expect .allDistinct ([n1, n5, n6, n7, n9, n10, n11, n12, n13, n14]);
86+ Expect .allDistinct ([n1, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14]);
9987
100- Expect .identical (clist, n6.left);
101- Expect .identical (clist, n10.left);
102- Expect .identical (clist, n12.left);
103- Expect .identical (clist, n13.left);
104- Expect .identical (clist, n14.left);
88+ Expect
89+ .allIdentical ([clist, n6.left, n10.left, n12.left, n13.left, n14.left]);
10590 Expect .allDistinct ([n5.left, n7.left, n9.left, n11.left]);
10691
107- Expect .identical (cmap, n5.right);
108- Expect .identical (cmap, n9.right);
109- Expect .identical (cmap, n12.right);
110- Expect .identical (cmap, n13.right);
111- Expect .identical (cmap, n14.right);
92+ Expect .allIdentical (
93+ [cmap, n5.right, n9.right, n12.right, n13.right, n14.right]);
11294 Expect .allDistinct ([n6.right, n7.right, n10.right, n11.right]);
11395
11496 const n20 = const N (const C (42 ), const < int > [37 ]);
@@ -124,21 +106,13 @@ main() {
124106 var n30 = N (c42, clist);
125107 var n31 = N (cc42, list);
126108
127- Expect .identical (n20, n21);
128- Expect .identical (n20, n22);
129- Expect .identical (n20, n23);
130- Expect .identical (n20, n24);
131- Expect .allDistinct ([n20, n25]);
132- Expect .allDistinct ([n20, n26]);
133- Expect .allDistinct ([n20, n27]);
134- Expect .allDistinct ([n28, n29, n30, n31]);
135- Expect .allDistinct ([cc42, n28.left]);
136- Expect .allDistinct ([cc42, n29.left]);
109+ Expect .allIdentical ([n20, n21, n22, n23, n24]);
110+ Expect .allDistinct ([n20, n25, n26, n27, n28, n29, n30, n31]);
111+
112+ Expect .allDistinct ([cc42, n28.left, n29.left]);
137113 Expect .identical (cc42, n30.left);
138114 Expect .identical (cc42, n31.left);
139- Expect .identical (clist, n29.right);
140- Expect .identical (clist, n30.right);
141- Expect .identical (clist, n31.right);
115+ Expect .allIdentical ([clist, n29.right, n30.right, n31.right]);
142116 Expect .notIdentical (clist, n28.right);
143117 }
144118
@@ -178,25 +152,13 @@ main() {
178152 var l30 = [c42, clist];
179153 var l31 = [cc42, list];
180154
181- Expect .identical (l20, l21);
182- Expect .identical (l20, l22);
183- Expect .identical (l20, l23);
184- Expect .identical (l20, l24);
155+ Expect .allIdentical ([l20, l21, l22, l23, l24]);
185156 // List literals are never const unless in const context.
186157 Expect .allDistinct ([l20, l25, l26, l27, l28, l29, l30, l31]);
187- Expect .identical (cc42, l25[0 ]);
188- Expect .allDistinct ([cc42, l26[0 ]]);
189- Expect .allDistinct ([cc42, l27[0 ]]);
190- Expect .allDistinct ([cc42, l28[0 ]]);
191- Expect .allDistinct ([cc42, l29[0 ]]);
192- Expect .identical (cc42, l30[0 ]);
193- Expect .identical (cc42, l31[0 ]);
194- Expect .identical (clist, l25[1 ]);
195- Expect .identical (clist, l26[1 ]);
196- Expect .identical (clist, l27[1 ]);
197- Expect .identical (clist, l29[1 ]);
198- Expect .identical (clist, l30[1 ]);
199- Expect .identical (clist, l31[1 ]);
158+ Expect .allIdentical ([cc42, l25[0 ], l30[0 ], l31[0 ]]);
159+ Expect .allDistinct ([cc42, l26[0 ], l27[0 ], l28[0 ], l29[0 ]]);
160+ Expect
161+ .allIdentical ([clist, l25[1 ], l26[1 ], l27[1 ], l29[1 ], l30[1 ], l31[1 ]]);
200162 Expect .notIdentical (clist, l28[1 ]);
201163 }
202164
@@ -229,25 +191,23 @@ main() {
229191 var m30 = {c42: clist};
230192 var m31 = {cc42: list};
231193
232- Expect .identical (m20, m21);
233- Expect .identical (m20, m22);
234- Expect .identical (m20, m23);
235- Expect .identical (m20, m24);
194+ Expect .allIdentical ([m20, m21, m22, m23, m24]);
236195 // Map literals are never const unless in const context.
237196 Expect .allDistinct ([m20, m25, m26, m27, m28, m29, m30, m31]);
238197 Expect .identical (cc42, m25.keys.first);
239- Expect .allDistinct ([cc42, m26.keys.first]);
240- Expect .allDistinct ([cc42, m27.keys.first]);
241- Expect .allDistinct ([cc42, m28.keys.first]);
242- Expect .allDistinct ([cc42, m29.keys.first]);
198+ Expect .allDistinct (
199+ [cc42, m26.keys.first, m27.keys.first, m28.keys.first, m29.keys.first]);
243200 Expect .identical (cc42, m30.keys.first);
244201 Expect .identical (cc42, m31.keys.first);
245- Expect .identical (clist, m25.values.first);
246- Expect .identical (clist, m26.values.first);
247- Expect .identical (clist, m27.values.first);
248- Expect .identical (clist, m29.values.first);
249- Expect .identical (clist, m30.values.first);
250- Expect .identical (clist, m31.values.first);
202+ Expect .allIdentical ([
203+ clist,
204+ m25.values.first,
205+ m26.values.first,
206+ m27.values.first,
207+ m29.values.first,
208+ m30.values.first,
209+ m31.values.first
210+ ]);
251211 Expect .notIdentical (clist, m28.values.first);
252212 }
253213}
0 commit comments