diff --git a/Language/Expressions/Constants/constant_list_t01.dart b/Language/Expressions/Constants/constant_list_t01.dart index 836397129f..ca384829e1 100644 --- a/Language/Expressions/Constants/constant_list_t01.dart +++ b/Language/Expressions/Constants/constant_list_t01.dart @@ -6,16 +6,30 @@ /// change, and that can be evaluated entirely at compile time. /// A constant expression is one of the following: /// . . . -/// • A constant list literal. -/// @description Checks that a constant list literal can be an element of -/// a constant list literal and is, therefore, a constant expression. +/// • A constant list literal, const [e1, ..., en], or [e1,..., en] that +/// occurs in a constant context, is a potentially constant expression if T is +/// a constant type expression, and e1, . . . , en are constant expressions. +/// It is further a constant expression if the list literal evaluates to an +/// object. +/// +/// @description Checks that a constant list literal of the form +/// `const [e1, ..., en]`, or `[e1, ..., en]` that occurs in a constant +/// context are constants /// @author iefremov import '../../../Utils/expect.dart'; -final constList = const [const ["hello", "world"]]; - main() { - Expect.isTrue(constList is List); - Expect.runtimeIsType(constList); + const c1 = [1, 2]; + var c2 = const [1, 2]; + + var c3 = const []; + const List c4 = []; + + const c5 = [[], {}, ()]; + var c6 = const [[], {}, ()]; + + Expect.identical(c1, c2); + Expect.identical(c3, c4); + Expect.identical(c5, c6); } diff --git a/Language/Expressions/Constants/constant_list_t02.dart b/Language/Expressions/Constants/constant_list_t02.dart index 81ca035302..bbe1babe3a 100644 --- a/Language/Expressions/Constants/constant_list_t02.dart +++ b/Language/Expressions/Constants/constant_list_t02.dart @@ -6,21 +6,28 @@ /// change, and that can be evaluated entirely at compile time. /// A constant expression is one of the following: /// . . . -/// • A constant list literal. -/// @description Checks that a non-constant list literal cannot be assigned to -/// a constant variable. +/// • A constant list literal, const [e1, ..., en], or [e1,..., en] that +/// occurs in a constant context, is a potentially constant expression if T is +/// a constant type expression, and e1, . . . , en are constant expressions. +/// It is further a constant expression if the list literal evaluates to an +/// object. +/// +/// @description Checks that it is a compile-time error if in a constant list +/// literal of the form const `[e1, ..., en]`, or `[e1, ..., en]`, `T` is +/// not a constant type expression /// @author iefremov -/// @reviewer rodionov - -var nonconstant = [1, 2, 3]; -const a = nonconstant; -// ^ +test() { + const c1 = []; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + print(const []); +// ^ // [analyzer] unspecified // [cfe] unspecified +} main() { - try { - print(a); - } catch (x) {} + print(test); } diff --git a/Language/Expressions/Constants/constant_list_t03.dart b/Language/Expressions/Constants/constant_list_t03.dart index 50796940e8..3d5fa8b4c5 100644 --- a/Language/Expressions/Constants/constant_list_t03.dart +++ b/Language/Expressions/Constants/constant_list_t03.dart @@ -6,7 +6,12 @@ /// change, and that can be evaluated entirely at compile time. /// A constant expression is one of the following: /// . . . -/// • A constant list literal. +/// • A constant list literal, const [e1, ..., en], or [e1,..., en] that +/// occurs in a constant context, is a potentially constant expression if T is +/// a constant type expression, and e1, . . . , en are constant expressions. +/// It is further a constant expression if the list literal evaluates to an +/// object. +/// /// @description Checks that a non-constant variable cannot be used in a /// constant list literal. /// @author sgrekhov22@gmail.com diff --git a/Language/Expressions/Constants/constant_map_t01.dart b/Language/Expressions/Constants/constant_map_t01.dart index e7d25ed3b5..881fc1e17c 100644 --- a/Language/Expressions/Constants/constant_map_t01.dart +++ b/Language/Expressions/Constants/constant_map_t01.dart @@ -5,17 +5,30 @@ /// @assertion A constant expression is an expression whose value can never /// change, and that can be evaluated entirely at compile time. /// A constant expression is one of the following: -/// . . . -/// • A constant map literal. -/// @description Checks that a constant map literal can be an element of -/// a constant list literal and is, therefore, a constant expression. +/// ... +/// A constant map literal, const {k1: v1, ..., kn: vn}, or +/// {k1: v1, ..., kn: vn} that occurs in a constant context, is a +/// potentially constant expression. It is further a constant expression if the +/// map literal evaluates to an object. +/// +/// @description Checks that a constant map literal of the form +/// `const {k1: v1, ..., kn: vn}`, or `{k1: v1, ..., kn: vn}` that +/// occurs in a constant context are constants /// @author iefremov import '../../../Utils/expect.dart'; -final constMap = const {"a" : 1, "b" : 2}; - main() { - Expect.isTrue(constMap is Map); - Expect.runtimeIsType(constMap); + const c1 = {"one": 1, "two": 2}; + var c2 = const {"one": 1, "two": 2}; + + var c3 = const {}; + const Map c4 = {}; + + const c5 = {[]: [], {}: {}, (): ()}; + var c6 = const {[]: [], {}: {}, (): ()}; + + Expect.identical(c1, c2); + Expect.identical(c3, c4); + Expect.identical(c5, c6); } diff --git a/Language/Expressions/Constants/constant_map_t02.dart b/Language/Expressions/Constants/constant_map_t02.dart index fc2de39b63..d891179766 100644 --- a/Language/Expressions/Constants/constant_map_t02.dart +++ b/Language/Expressions/Constants/constant_map_t02.dart @@ -5,21 +5,29 @@ /// @assertion A constant expression is an expression whose value can never /// change, and that can be evaluated entirely at compile time. /// A constant expression is one of the following: -/// . . . -/// • A constant map literal. -/// @description Checks that a non-constant map literal cannot be assigned to -/// a constant variable. +/// ... +/// A constant map literal, const {k1: v1, ..., kn: vn}, or +/// {k1: v1, ..., kn: vn} that occurs in a constant context, is a +/// potentially constant expression. It is further a constant expression if the +/// map literal evaluates to an object. +/// +/// @description Checks that it is a compile-time error if in a constant map +/// literal of the form `const {k1: v1, ..., kn: vn`, or +/// `{k1: v1, ..., kn: vn}`, `K` or `V` are not a constant type +/// expressions /// @author iefremov - -var b = {"a" : "b"}; -const a = b; -// ^ +test() { + const c1 = {}; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + print(const {}); +// ^ // [analyzer] unspecified // [cfe] unspecified +} main() { - try { - print(a); - } catch (x) {} + print(test); } diff --git a/Language/Expressions/Constants/constant_map_t03.dart b/Language/Expressions/Constants/constant_map_t03.dart index 100beac16f..d9ed257ece 100644 --- a/Language/Expressions/Constants/constant_map_t03.dart +++ b/Language/Expressions/Constants/constant_map_t03.dart @@ -5,8 +5,12 @@ /// @assertion A constant expression is an expression whose value can never /// change, and that can be evaluated entirely at compile time. /// A constant expression is one of the following: -/// . . . -/// • A constant map literal. +/// ... +/// A constant map literal, const {k1: v1, ..., kn: vn}, or +/// {k1: v1, ..., kn: vn} that occurs in a constant context, is a +/// potentially constant expression. It is further a constant expression if the +/// map literal evaluates to an object. +/// /// @description Checks that a non-constant map literal cannot be assigned to /// a constant variable. /// @author sgrekhov22@gmail.com diff --git a/Language/Expressions/Constants/constant_set_t02.dart b/Language/Expressions/Constants/constant_set_t02.dart index 648585ed0f..ad19932c3e 100644 --- a/Language/Expressions/Constants/constant_set_t02.dart +++ b/Language/Expressions/Constants/constant_set_t02.dart @@ -17,7 +17,7 @@ /// object. /// /// @description Checks that it is a compile-time error if in a constant set -/// literal of the form const `{e1, ..., en}`, or `{e1, ..., en}`, `T` is +/// literal of the form `const {e1, ..., en}`, or `{e1, ..., en}`, `T` is /// not a constant type expression /// @author sgrekhov22@gmail.com diff --git a/Language/Expressions/Constants/constant_set_t03.dart b/Language/Expressions/Constants/constant_set_t03.dart index 59b2e1ada2..7c5736c8ce 100644 --- a/Language/Expressions/Constants/constant_set_t03.dart +++ b/Language/Expressions/Constants/constant_set_t03.dart @@ -17,7 +17,7 @@ /// object. /// /// @description Checks that it is a compile-time error if in a constant set -/// literal of the form const `{e1, ..., en}`, or `{e1, ..., en}`, any of +/// literal of the form `const {e1, ..., en}`, or `{e1, ..., en}`, any of /// `ei` is not a constant expression /// @author sgrekhov22@gmail.com @@ -29,7 +29,7 @@ const a = {nonconstant1}; // [cfe] unspecified Set get test => const {1, nonconstant1}; -// ^^^^^^^^^^^^ +// ^^^^^^^^^^^^ // [analyzer] unspecified // [cfe] unspecified diff --git a/Language/Expressions/Constants/parenthesized_expression_t01.dart b/Language/Expressions/Constants/parenthesized_expression_t01.dart index 93623b8c0b..a69527cf38 100644 --- a/Language/Expressions/Constants/parenthesized_expression_t01.dart +++ b/Language/Expressions/Constants/parenthesized_expression_t01.dart @@ -32,13 +32,19 @@ const constList = const [ (const {}), (1 == 1), (identical('', null)), + (identical((), ())), (true != false), (!true), (false && false), (1 ^ 2), (~0), (2 + 0.5), - (1 * 1) + (1 * 1), + (()), + ((1,)), + ((x: 2)), + ((1 < 2), (2 > 3)), + (((0))) ]; main() {