Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions Language/Expressions/Constants/literal_boolean_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal boolean.
/// @description Checks that various literal booleans can be elements of a
/// constant list literal and are, therefore, constant expressions.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal boolean, `true` or `false`, is a potentially constant and
/// constant expression.
///
/// @description Checks that various literal booleans are constants.
/// @author iefremov

import '../../../Utils/expect.dart';

final constList = const [
true,
false
];
const _true = true;
const _false = false;

main() {
Expect.isTrue(constList is List);
Expect.runtimeIsType<List>(constList);
print(_true);
print(_false);
}
33 changes: 18 additions & 15 deletions Language/Expressions/Constants/literal_number_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal number.
/// @description Checks that 0xFFffFFffFFffFFff can be elements of a
/// constant list literal and шы, therefore, constant expressions. Minus sign
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal number is a potentially constant and constant expression if it
/// evaluates to an instance of type `int` or `double`.
///
/// @description Checks that `0xFFffFFffFFffFFff` can be elements of a
/// constant list literal and is, therefore, a constant expressions. Minus sign
/// is not a part of a number literal so those are not included in this test.
/// Should be excluded for the web runs as 0xFFffFFffFFffFFff is not allowed as
/// a literal number there.
/// Should be excluded for the web runs as `0xFFffFFffFFffFFff` is not allowed
/// as a literal number there.
/// @author iefremov

import '../../../Utils/expect.dart';

final constList = const [
0xFFffFFffFFffFFff
];
const c = 0xFFffFFffFFffFFff;

main() {
Expect.isTrue(constList is List);
Expect.runtimeIsType<List>(constList);
print(c);
}
25 changes: 15 additions & 10 deletions Language/Expressions/Constants/literal_number_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal number.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal number is a potentially constant and constant expression if it
/// evaluates to an instance of type `int` or `double`.
///
/// @description Checks that various literal numbers can be elements of a
/// constant list literal and are, therefore, constant expressions. Minus sign
/// is not a part of a number literal so those are not included in this test.
/// @note Should be OK both with dart and dart2js runs.
/// @author iarkh@unipro.ru

import '../../../Utils/expect.dart';

final constList = const [
0,
1,
2147483647,
-.2147483648E10,
.2147483648E10,
.9223372036854775807,
9223372036854775808E-100,
-9223372036854775808e0,
9223372036854775808e0,
9223372036854775809e+9223372036854775809,
92233720368547758080.9223372036854775808e-00124155125325235,
92233720368547758080.9223372036854775808e+92233720368547758080,
Expand All @@ -31,6 +37,5 @@ final constList = const [
];

main() {
Expect.isTrue(constList is List);
Expect.runtimeIsType<List>(constList);
print(constList);
}
32 changes: 18 additions & 14 deletions Language/Expressions/Constants/literal_string_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal string where any interpolated expression is a compile-time
/// constant that evaluates to a numeric, string or boolean value or to null.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal string with string interpolations with expressions `e1, ..., en`
/// is a potentially constant expression if `e1, ..., en` are potentially
/// constant expressions. The literal is further a constant expression if
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
/// `double`, `String`, `bool`, or `Null`.
///
/// @description Checks that various literal strings can be elements of a
/// constant list literal and are, therefore, constant expressions.
/// @author iefremov

import '../../../Utils/expect.dart';

final constList = const [
"",
"test",
Expand Down Expand Up @@ -56,10 +63,7 @@ final constListConcatenation = const [
];

main() {
Expect.isTrue(constList is List);
Expect.isTrue(constListInterpolation is List);
Expect.isTrue(constListConcatenation is List);
Expect.runtimeIsType<List>(constList);
Expect.runtimeIsType<List>(constListInterpolation);
Expect.runtimeIsType<List>(constListConcatenation);
print(constList);
print(constListInterpolation);
print(constListConcatenation);
}
49 changes: 38 additions & 11 deletions Language/Expressions/Constants/literal_string_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,49 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal string where any interpolated expression is a compile-time
/// constant that evaluates to a numeric, string or boolean value or to null.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal string with string interpolations with expressions `e1, ..., en`
/// is a potentially constant expression if `e1, ..., en` are potentially
/// constant expressions. The literal is further a constant expression if
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
/// `double`, `String`, `bool`, or `Null`.
///
/// @description Checks that a string literal that involves string interpolation,
/// that is a constant expression not evaluated to numeric, string or boolean
/// value, cannot be assigned to a constant variable.
/// that is a constant expression not evaluated to `int`, `double`, `String`,
/// `bool`, or `Null` cannot be assigned to a constant variable.
/// @author iefremov

const l = "${const {'k1': 1, 'k2': 2}}";
// ^
class C {
const C();
}

const c1 = "${const {'k1': 1, 'k2': 2}}";
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

const c2 = "${#foo}";
// ^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

const c = C();

const c3 = "$c";
// ^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(l);
print(c1);
print(c2);
print(c3);
}
25 changes: 17 additions & 8 deletions Language/Expressions/Constants/literal_string_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal string where any interpolated expression is a compile-time
/// constant that evaluates to a numeric, string or boolean value or to null.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal string with string interpolations with expressions `e1, ..., en`
/// is a potentially constant expression if `e1, ..., en` are potentially
/// constant expressions. The literal is further a constant expression if
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
/// `double`, `String`, `bool`, or `Null`.
///
/// @description Checks that a string literal that involves string interpolation,
/// that evaluates to a numeric value, but not a constant expression,
/// cannot be assigned to a constant variable.
/// that evaluates to a numeric value, but not a constant expression, cannot be
/// assigned to a constant variable.
/// @author msyabro

foo() => 1;
Expand Down
21 changes: 15 additions & 6 deletions Language/Expressions/Constants/literal_string_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal string where any interpolated expression is a compile-time
/// constant that evaluates to a numeric, string or boolean value or to null.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal string with string interpolations with expressions `e1, ..., en`
/// is a potentially constant expression if `e1, ..., en` are potentially
/// constant expressions. The literal is further a constant expression if
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
/// `double`, `String`, `bool`, or `Null`.
///
/// @description Checks that a string literal that involves string interpolation,
/// that evaluates to a bool value and is a constant expression can be assigned
/// to a constant variable.
Expand Down
21 changes: 15 additions & 6 deletions Language/Expressions/Constants/literal_string_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal string where any interpolated expression is a compile-time
/// constant that evaluates to a numeric, string or boolean value or to null.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal string with string interpolations with expressions `e1, ..., en`
/// is a potentially constant expression if `e1, ..., en` are potentially
/// constant expressions. The literal is further a constant expression if
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
/// `double`, `String`, `bool`, or `Null`.
///
/// @description Checks that a string literal that involves string interpolation,
/// that evaluates to a string value, but not a constant expression, cannot be
/// assigned to a constant variable.
Expand Down
22 changes: 15 additions & 7 deletions Language/Expressions/Constants/literal_symbol_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @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 literal symbol.
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
/// A potentially constant expression is an expression that will generally yield
/// a constant value when the values of certain parameters are given. The
/// constant expressions is a subset of the potentially constant expressions
/// that can be evaluated at compile time.
///
/// The potentially constant expressions and constant expressions are the
/// following:
/// ...
/// • A literal symbol is a potentially constant and constant expression.
///
/// @description Checks that literal symbol can be assigned to a constant
/// variable.
/// @author ilya

const i1 = #foo;
import "../../../Utils/expect.dart";

const c = #foo;

main() {
i1;
Expect.identical(c, #foo);
}
Loading