Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: tests/language/compile_time_constant10_test.dart

Issue 10908287: Make identical(a,b) a compile-time constant in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 // Test that 'identical(a,b)' is a compile-time constant.
6
7 class C {
8 final x;
9 const C(this.x);
10 static f3(){}
11 static f4(){}
12 }
13
14 const i1 = 1;
15 const i2 = 2;
16 const d1 = 1.5;
17 const d2 = 2.5;
18 const b1 = true;
19 const b2 = false;
20 const s1 = "1";
21 const s2 = "2";
22 const l1 = const [1,2];
23 const l2 = const [2,3];
24 const m1 = const {"x": 1};
25 const m2 = const {"x": 2};
26 const c1 = const C(1);
27 const c2 = const C(2);
28 f1(){}
29 f2(){}
30 const id = identical;
31
32 class CT {
33 final x1;
34 final x2;
35 bool id;
36 const CT(var x1, var x2)
37 : this.x1 = x1, this.x2 = x2, this.id = identical(x1, x2);
38 void test(void expect(a,b), name) {
39 expect(id, "$name: identical($x1,$x2)");
40 }
41 }
42
43 const trueTests = const [
44 const CT(2 - 1, i1),
45 const CT(1 + 1, i2),
46 const CT(2.5 - 1.0, d1),
47 const CT(1.5 + 1.0, d2),
48 const CT(false || true, b1),
49 const CT(true && false, b2),
50 const CT('$i1', s1),
51 const CT('$i2', s2),
52 const CT(const [i1, 2], l1),
53 const CT(const [i2, 3], l2),
54 const CT(const {"x": i1}, m1),
55 const CT(const {"x": i2}, m2),
56 const CT(const C(i1), c1),
57 const CT(const C(i2), c2),
58 const CT(f1, f1),
59 const CT(f2, f2),
60 const CT(C.f3, C.f3),
61 const CT(C.f4, C.f4),
62 const CT(id, identical),
63 ];
64
65 const falseTests = const [
66 const CT(i1, i2),
67 const CT(d1, d2),
68 const CT(b1, b2),
69 const CT(s1, s2),
70 const CT(l1, l2),
71 const CT(m1, m2),
72 const CT(c1, c2),
73 const CT(f1, f2),
74 const CT(i1, d1),
75 const CT(d1, b1),
76 const CT(b1, s1),
77 const CT(s1, l1),
78 const CT(l1, m1),
79 const CT(m1, c1),
80 const CT(c1, f1),
81 const CT(f1, C.f3),
82 const CT(C.f3, identical),
83 const CT(identical, i1),
84 ];
85
86 // Not a constant if it's not written 'identical'.
87 const idtest = id(i1, i2); /// 01: compile-time error
88
89 // Not a constant if aliased? (Current interpretation, waiting for
90 // confirmation).
91 class T { /// 02: compile-time error
92 static const identical = id; /// 02: continued
93 static const idtest2 = identical(i1, i2); /// 02: continued
94 } /// 02: continued
95
96 main() {
97 for (int i = 0; i < trueTests.length; i++) {
98 trueTests[i].test(Expect.isTrue, "true[$i]");
99 }
100 for (int i = 0; i < falseTests.length; i++) {
101 falseTests[i].test(Expect.isFalse, "false[$i]");
102 }
103
104 var x = idtest; /// 01: continued
105 var x = T.idtest2; /// 02: continued
106 }
107
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698