John Messerly | bea9ae7 | 2015-09-16 13:28:49 -0700 | [diff] [blame] | 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 | import "package:expect/expect.dart"; |
| 6 | |
| 7 | main() { |
| 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 | |
| 37 | final F0 = 42; |
| 38 | final F1; /// 03: continued |
| 39 | final int F2 = 87; |
| 40 | final int F3; /// 04: continued |
| 41 | |
| 42 | class 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. |
| 50 | final P0 = const Point(0, 0); |
| 51 | final P1 = const Point(0, 0) + 1; |
| 52 | final P2 = new Point(0, 0); |
| 53 | final P3 = new Point(0, 0) + 1; |
| 54 | |
| 55 | // Check that we cannot have cyclic references in compile time |
| 56 | // expressions. |
| 57 | final A0 = 42; |
| 58 | final A1 = A0 + 1; |
| 59 | final A2 = A3 + 1; /// 08: continued |
| 60 | final A3 = A2 + 1; /// 08: continued |
| 61 | |
| 62 | class C0 { |
| 63 | static final X = const C1(); |
| 64 | } |
| 65 | |
| 66 | class 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. |
| 74 | final B0 = 42; |
| 75 | final B1 = "Hello"; |
| 76 | final B2 = "$B1 $B0"; |
| 77 | final B3 = B0 + B1; /// 10: continued |