|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | | -/// @assertion A constant expression is an expression whose value can never |
6 | | -/// change, and that can be evaluated entirely at compile time. |
7 | | -/// A constant expression is one of the following: |
8 | | -/// . . . |
9 | | -/// • A literal string where any interpolated expression is a compile-time |
10 | | -/// constant that evaluates to a numeric, string or boolean value or to null. |
| 5 | +/// @assertion All usages of ’constant’ in Dart are associated with compile time. |
| 6 | +/// A potentially constant expression is an expression that will generally yield |
| 7 | +/// a constant value when the values of certain parameters are given. The |
| 8 | +/// constant expressions is a subset of the potentially constant expressions |
| 9 | +/// that can be evaluated at compile time. |
| 10 | +/// |
| 11 | +/// The potentially constant expressions and constant expressions are the |
| 12 | +/// following: |
| 13 | +/// ... |
| 14 | +/// • A literal string with string interpolations with expressions `e1, ..., en` |
| 15 | +/// is a potentially constant expression if `e1, ..., en` are potentially |
| 16 | +/// constant expressions. The literal is further a constant expression if |
| 17 | +/// `e1, . . . , en` are constant expressions evaluating to instances of `int`, |
| 18 | +/// `double`, `String`, `bool`, or `Null`. |
| 19 | +/// |
11 | 20 | /// @description Checks that a string literal that involves string interpolation, |
12 | | -/// that is a constant expression not evaluated to numeric, string or boolean |
13 | | -/// value, cannot be assigned to a constant variable. |
| 21 | +/// that is a constant expression not evaluated to `int`, `double`, `String`, |
| 22 | +/// `bool`, or `Null` cannot be assigned to a constant variable. |
14 | 23 | /// @author iefremov |
15 | 24 |
|
16 | | -const l = "${const {'k1': 1, 'k2': 2}}"; |
17 | | -// ^ |
| 25 | +class C { |
| 26 | + const C(); |
| 27 | +} |
| 28 | + |
| 29 | +const c1 = "${const {'k1': 1, 'k2': 2}}"; |
| 30 | +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 31 | +// [analyzer] unspecified |
| 32 | +// [cfe] unspecified |
| 33 | + |
| 34 | +const c2 = "${#foo}"; |
| 35 | +// ^^^^^^^ |
| 36 | +// [analyzer] unspecified |
| 37 | +// [cfe] unspecified |
| 38 | + |
| 39 | +const c = C(); |
| 40 | + |
| 41 | +const c3 = "$c"; |
| 42 | +// ^^ |
18 | 43 | // [analyzer] unspecified |
19 | 44 | // [cfe] unspecified |
20 | 45 |
|
21 | 46 | main() { |
22 | | - print(l); |
| 47 | + print(c1); |
| 48 | + print(c2); |
| 49 | + print(c3); |
23 | 50 | } |
0 commit comments