Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Check that initializers of static final fields are compile time constants. | 4 // Check that initializers of static final fields are compile time constants. |
| 5 | 5 |
| 6 class Point { | 6 class Point { |
| 7 final x_; | 7 final x_; |
| 8 final y_; | 8 final y_; |
| 9 const Point(x, y) : x_ = x, y_ = y; | 9 const Point(x, y) : x_ = x, y_ = y; |
| 10 } | 10 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 Expect.equals(0, C2.Q.y_); | 35 Expect.equals(0, C2.Q.y_); |
| 36 | 36 |
| 37 // Nor the order of top level constants | 37 // Nor the order of top level constants |
| 38 Expect.equals(1, X.x_); | 38 Expect.equals(1, X.x_); |
| 39 Expect.equals(4, X.y_); | 39 Expect.equals(4, X.y_); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 class C2 { | 43 class C2 { |
| 44 static final Q = const Point(0, 0); | 44 static final Q = const Point(0, 0); |
| 45 // TODO(zundel): Was it intentional to forward reference O, N? | |
|
ngeoffray
2011/10/17 10:59:38
Does it matter?
zundel
2011/10/17 14:14:26
As per Florian's request, moved to a separate test
| |
| 46 // Compiler doesn't recognize the type of O, N as int in that case. | |
|
ngeoffray
2011/10/17 10:59:38
Maybe file a bug to fix that in dartc?
zundel
2011/10/17 14:14:26
Codesite issue 120
| |
| 45 static final P = 2 * (O - N); | 47 static final P = 2 * (O - N); |
| 46 static final O = 1 + 3; | 48 static final O = 1 + 3; |
| 47 static final N = 1; | 49 static final N = 1; |
| 48 } | 50 } |
| 49 | 51 |
| 50 // Top level final | 52 // Top level final |
| 51 final X = const Point(C2.N, C2.O); | 53 final X = const Point(C2.N, C2.O); |
| 52 | 54 |
| 53 main() { | 55 main() { |
| 54 ConstInitTest.testMain(); | 56 ConstInitTest.testMain(); |
| 55 } | 57 } |
| OLD | NEW |