-
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
Add constant expressions tests.Part 3.
- Loading branch information
Showing
8 changed files
with
451 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t12.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,50 @@ | ||
// Copyright (c) 2024, 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 A static member shorthand expression should be a potentially | ||
/// constant expression if the corresponding explicit static member plus | ||
/// selectors expression would be, which currently means that it's a potentially | ||
/// constant expression if and only if it's a constant expression. | ||
/// | ||
/// @description Checks that a static member shorthand expression can be used in | ||
/// a right operand of a constant `e1 == e2` expression. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class C { | ||
static const C answer = const C(42); | ||
final int v; | ||
const C(this.v); | ||
} | ||
|
||
mixin M on C { | ||
static const M answer = const MC(42); | ||
} | ||
|
||
class MC extends C with M { | ||
const MC(super.v); | ||
} | ||
|
||
enum E { | ||
e0; | ||
static const E answer = E.e0; | ||
} | ||
|
||
extension type const ET(int v) { | ||
static const ET answer = const ET(42); | ||
} | ||
|
||
main() { | ||
const b1 = C(42) == .answer; | ||
Expect.isTrue(b1); | ||
const b2 = (MC(42) as M) == .answer; | ||
Expect.isTrue(b2); | ||
const b3 = E.e0 == .answer; | ||
Expect.isTrue(b3); | ||
const b4 = ET(42) == .answer; | ||
Expect.isTrue(b4); | ||
} |
57 changes: 57 additions & 0 deletions
57
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t13.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,57 @@ | ||
// Copyright (c) 2024, 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 A static member shorthand expression should be a potentially | ||
/// constant expression if the corresponding explicit static member plus | ||
/// selectors expression would be, which currently means that it's a potentially | ||
/// constant expression if and only if it's a constant expression. | ||
/// | ||
/// @description Checks that it is compile-time error if a non-constant static | ||
/// member shorthand expression is used in a right operand of a constant | ||
/// `e1 == e2` expression. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
class C { | ||
static C answer = const C(42); | ||
final int v; | ||
const C(this.v); | ||
} | ||
|
||
mixin M on C { | ||
static const M answer = const MC(42); | ||
} | ||
|
||
class MC extends C with M { | ||
const MC(super.v); | ||
} | ||
|
||
enum E { | ||
e0; | ||
static E answer = E.e0; | ||
} | ||
|
||
extension type const ET(int v) { | ||
static ET answer = const ET(42); | ||
} | ||
|
||
main() { | ||
const b1 = C(42) == .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const b2 = (MC(42) as M) == .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const b3 = E.e0 == .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const b4 = ET(42) == .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
50 changes: 50 additions & 0 deletions
50
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t14.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,50 @@ | ||
// Copyright (c) 2024, 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 A static member shorthand expression should be a potentially | ||
/// constant expression if the corresponding explicit static member plus | ||
/// selectors expression would be, which currently means that it's a potentially | ||
/// constant expression if and only if it's a constant expression. | ||
/// | ||
/// @description Checks that a static member shorthand expression can be used in | ||
/// a right operand of a constant `e1 != e2` expression. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class C { | ||
static const C answer = const C(42); | ||
final int v; | ||
const C(this.v); | ||
} | ||
|
||
mixin M on C { | ||
static const M answer = const MC(42); | ||
} | ||
|
||
class MC extends C with M { | ||
const MC(super.v); | ||
} | ||
|
||
enum E { | ||
e0; | ||
static const E answer = E.e0; | ||
} | ||
|
||
extension type const ET(int v) { | ||
static const ET answer = const ET(42); | ||
} | ||
|
||
main() { | ||
const b1 = C(42) != .answer; | ||
Expect.isFalse(b1); | ||
const b2 = (MC(42) as M) != .answer; | ||
Expect.isFalse(b2); | ||
const b3 = E.e0 != .answer; | ||
Expect.isFalse(b3); | ||
const b4 = ET(42) != .answer; | ||
Expect.isFalse(b4); | ||
} |
57 changes: 57 additions & 0 deletions
57
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t15.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,57 @@ | ||
// Copyright (c) 2024, 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 A static member shorthand expression should be a potentially | ||
/// constant expression if the corresponding explicit static member plus | ||
/// selectors expression would be, which currently means that it's a potentially | ||
/// constant expression if and only if it's a constant expression. | ||
/// | ||
/// @description Checks that it is compile-time error if a non-constant static | ||
/// member shorthand expression is used in a right operand of a constant | ||
/// `e1 != e2` expression. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
class C { | ||
static C answer = const C(42); | ||
final int v; | ||
const C(this.v); | ||
} | ||
|
||
mixin M on C { | ||
static const M answer = const MC(42); | ||
} | ||
|
||
class MC extends C with M { | ||
const MC(super.v); | ||
} | ||
|
||
enum E { | ||
e0; | ||
static E answer = E.e0; | ||
} | ||
|
||
extension type const ET(int v) { | ||
static ET answer = const ET(42); | ||
} | ||
|
||
main() { | ||
const b1 = C(42) != .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const b2 = (MC(42) as M) != .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const b3 = E.e0 != .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const b4 = ET(42) != .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
54 changes: 54 additions & 0 deletions
54
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t16.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,54 @@ | ||
// Copyright (c) 2024, 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 A static member shorthand expression should be a potentially | ||
/// constant expression if the corresponding explicit static member plus | ||
/// selectors expression would be, which currently means that it's a potentially | ||
/// constant expression if and only if it's a constant expression. | ||
/// | ||
/// @description Checks that a static member shorthand expression can be used in | ||
/// a constant `e1 ? e2 : e3` expression. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class C { | ||
static const C one = const C(1); | ||
static const C two = const C(2); | ||
final int v; | ||
const C(this.v); | ||
} | ||
|
||
mixin M on C { | ||
static const M one = const MC(1); | ||
static const M two = const MC(2); | ||
} | ||
|
||
class MC extends C with M { | ||
const MC(super.v); | ||
} | ||
|
||
enum E { | ||
e1, e2; | ||
static const E one = E.e1; | ||
static const E two = E.e2; | ||
} | ||
|
||
extension type const ET(int v) { | ||
static const ET one = const ET(1); | ||
static const ET two = const ET(2); | ||
} | ||
|
||
main() { | ||
const C c = 2 > 1 ? .one : .two; | ||
Expect.identical(const C(1), c); | ||
const M m = 2 < 1 ? .one : .two; | ||
Expect.identical(const MC(2), m); | ||
const E e = 2 > 1 ? .one : .two; | ||
Expect.identical(E.e1, e); | ||
const ET et = 2 < 1 ? .one : .two; | ||
Expect.identical(const ET(2), et); | ||
} |
60 changes: 60 additions & 0 deletions
60
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t17.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,60 @@ | ||
// Copyright (c) 2024, 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 A static member shorthand expression should be a potentially | ||
/// constant expression if the corresponding explicit static member plus | ||
/// selectors expression would be, which currently means that it's a potentially | ||
/// constant expression if and only if it's a constant expression. | ||
/// | ||
/// @description Checks that it is a compile-time error if a non-constant static | ||
/// member shorthand expression is used in a constant `e1 ? e2 : e3` expression. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
class C { | ||
static C one = const C(1); | ||
static const C two = const C(2); | ||
final int v; | ||
const C(this.v); | ||
} | ||
|
||
mixin M on C { | ||
static M one = const MC(1); | ||
static const M two = const MC(2); | ||
} | ||
|
||
class MC extends C with M { | ||
const MC(super.v); | ||
} | ||
|
||
enum E { | ||
e1, e2; | ||
static const E one = E.e1; | ||
static E two = E.e2; | ||
} | ||
|
||
extension type const ET(int v) { | ||
static const ET one = const ET(1); | ||
static ET two = const ET(2); | ||
} | ||
|
||
main() { | ||
const C c = 2 > 1 ? .one : .two; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const M m = 2 < 1 ? .one : .two; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const E e = 2 > 1 ? .one : .two; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const ET et = 2 < 1 ? .one : .two; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
63 changes: 63 additions & 0 deletions
63
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t18.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,63 @@ | ||
// Copyright (c) 2024, 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 A static member shorthand expression should be a potentially | ||
/// constant expression if the corresponding explicit static member plus | ||
/// selectors expression would be, which currently means that it's a potentially | ||
/// constant expression if and only if it's a constant expression. | ||
/// | ||
/// @description Checks that a static member shorthand expression can be used in | ||
/// a constant `e1 ?? e2` expression. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class C { | ||
static const C one = const C(1); | ||
static const C? two = null; | ||
final int v; | ||
const C(this.v); | ||
} | ||
|
||
mixin M on C { | ||
static const M one = const MC(1); | ||
static const M? two = null; | ||
} | ||
|
||
class MC extends C with M { | ||
const MC(super.v); | ||
} | ||
|
||
enum E { | ||
e1, e2; | ||
static const E one = E.e1; | ||
static const E? two = null; | ||
} | ||
|
||
extension type const ET(int v) { | ||
static const ET one = const ET(1); | ||
static const ET? two = null; | ||
} | ||
|
||
main() { | ||
const C c = .two ?? .one; | ||
Expect.identical(const C(1), c); | ||
const M m = .two ?? .one; | ||
Expect.identical(const MC(1), m); | ||
const E e = .two ?? .one; | ||
Expect.identical(E.e1, e); | ||
const ET et = .two ?? .one; | ||
Expect.identical(const ET(1), et); | ||
|
||
const c2 = (C(1) as C?) ?? .one; | ||
Expect.identical(const C(1), c2); | ||
const m2 = (MC(1) as M?) ?? .one; | ||
Expect.identical(const MC(1), m2); | ||
const e2 = (E.e1 as E?) ?? .one; | ||
Expect.identical(E.e1, e2); | ||
const et2 = (ET(1) as ET?) ?? .one; | ||
Expect.identical(const ET(1), et2); | ||
} |
Oops, something went wrong.