blob: 3ac879dffc709132699ff1abffd64a732d60c9ec [file] [log] [blame]
John Messerlybea9ae72015-09-16 13:28:49 -07001// 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
5import "package:expect/expect.dart";
6
7main() {
8 final f0 = 42;
9 final f1; /// 01: compile-time error
10 final int f2 = 87;
11 final int f3; /// 02: compile-time error
12 Expect.equals(42, f0);
13 Expect.equals(87, f2);
14
15 Expect.equals(42, F0);
16 Expect.equals(null, F1); /// 03: compile-time error
17 Expect.equals(87, F2);
18 Expect.equals(null, F3); /// 04: compile-time error
19
20 Expect.isTrue(P0 is Point);
21 Expect.isTrue(P1 is int);
22 Expect.isTrue(P2 is Point);
23 Expect.isTrue(P3 is int);
24
25 Expect.isTrue(A0 is int);
26 Expect.isTrue(A1 is int);
27 Expect.isTrue(A2 is int); /// 08: runtime error
28 Expect.isTrue(A3 is int); /// 08: continued
29
30 Expect.isTrue(C0.X is C1);
31 Expect.isTrue(C0.X.x is C1); /// 09: compile-time error
32
33 Expect.equals("Hello 42", B2);
34 Expect.equals("42Hello", B3); /// 10: runtime error
35}
36
37final F0 = 42;
38final F1; /// 03: continued
39final int F2 = 87;
40final int F3; /// 04: continued
41
42class Point {
43 final x, y;
44 const Point(this.x, this.y);
45 operator +(int other) => x;
46}
47
48// Check that compile time expressions can include invocations of
49// user-defined final constructors.
50final P0 = const Point(0, 0);
51final P1 = const Point(0, 0) + 1;
52final P2 = new Point(0, 0);
53final P3 = new Point(0, 0) + 1;
54
55// Check that we cannot have cyclic references in compile time
56// expressions.
57final A0 = 42;
58final A1 = A0 + 1;
59final A2 = A3 + 1; /// 08: continued
60final A3 = A2 + 1; /// 08: continued
61
62class C0 {
63 static final X = const C1();
64}
65
66class C1 {
67 const C1()
68 : x = C0.X /// 09: continued
69 ;
70 final x = null;
71}
72
73// Check that sub-expressions of binary + are numeric.
74final B0 = 42;
75final B1 = "Hello";
76final B2 = "$B1 $B0";
77final B3 = B0 + B1; /// 10: continued