-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Language/Expressions/Constants/no_other_constant_expressions_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// 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 There are no other constant expressions. | ||
/// | ||
/// @description Checks that a null-check operator cannot be used in a constant | ||
/// expression. | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 59800 | ||
const one = 1!; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const int? two = 2; | ||
const int nonNullableTwo = two!; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const int three = 1 + two!; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
print(one); | ||
print(two); | ||
print(nonNullableTwo); | ||
print(three); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// 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 The potentially constant expressions and constant expressions are | ||
/// the following: | ||
/// ... | ||
/// • An expression of the form `e.length` is potentially constant if `e` is a | ||
/// potentially constant expression. It is further constant if `e` is a | ||
/// constant expression that evaluates to an instance of [String], such that | ||
/// `length` denotes an instance getter invocation. | ||
/// | ||
/// @description Checks that it is a compile-time error to use a null-aware | ||
/// operator `?.` in a constant `String.length` expression. | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 59904 | ||
const c1 = "x"?.length; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const String? one = "1"; | ||
const int? c2 = one?.length; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const String? three = null; | ||
const int? c3 = three?.length; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const int? c4 = three == null ? null : three?.length; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
print(c1); | ||
print(c2); | ||
print(c3); | ||
print(c4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// 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 The potentially constant expressions and constant expressions are | ||
/// the following: | ||
/// ... | ||
/// • An expression of the form `e.length` is potentially constant if `e` is a | ||
/// potentially constant expression. It is further constant if `e` is a | ||
/// constant expression that evaluates to an instance of [String], such that | ||
/// `length` denotes an instance getter invocation. | ||
/// | ||
/// @description Checks that it is a compile-time error to use a cascade member | ||
/// access in a constant `String.length` expression. | ||
/// @author sgrekhov22@gmail.com | ||
const c1 = "x"..length; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const String one = "1"; | ||
const c2 = one..length; | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
print(c1); | ||
print(c2); | ||
} |