forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2976. Add constant expressions tests.Part 2.
- Loading branch information
Showing
15 changed files
with
545 additions
and
21 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
LanguageFeatures/Static-access-shorthand/constant_expression_A10_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) 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 qualified reference to a static constant variable | ||
/// that is not qualified by a deferred prefix, is a potentially constant and | ||
/// constant expression | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../../Utils/expect.dart'; | ||
import 'shorthand_lib.dart'as p; | ||
|
||
main() { | ||
const p.C c = .answer; | ||
Expect.identical(42, c.t); | ||
|
||
const p.M m = .answer; | ||
Expect.identical(42, m.t); | ||
|
||
const p.E e = .answer; | ||
Expect.identical(42, e.t); | ||
|
||
const p.ET et = .answer; | ||
Expect.identical(42, et.t); | ||
} |
32 changes: 32 additions & 0 deletions
32
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t02.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) 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 | ||
/// the initializer list of a constant constructor. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class A { | ||
final int id; | ||
const A(this.id); | ||
static const A answer = const A(42); | ||
} | ||
|
||
class C { | ||
final A a; | ||
const C(this.a); | ||
const C.fromAnswer() : a = .answer; | ||
} | ||
|
||
main() { | ||
Expect.identical(42, C.fromAnswer().a.id); | ||
} |
35 changes: 35 additions & 0 deletions
35
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t03.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,35 @@ | ||
// 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 the initializer list of the constant | ||
/// constructor. | ||
/// @author [email protected] | ||
/// @issue 59804 | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
class A { | ||
int id; | ||
A(this.id); | ||
static A answer = A(42); | ||
} | ||
|
||
class C { | ||
final A a; | ||
const C(this.a); | ||
const C.fromAnswer() : a = .answer; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(C); | ||
} |
46 changes: 46 additions & 0 deletions
46
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t04.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,46 @@ | ||
// 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 list literal. | ||
/// @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() { | ||
Expect.identical(const [C(42)], const <C>[.answer]); | ||
Expect.identical(const <M>[MC(42)], const <M>[.answer]); | ||
Expect.identical(const [E.e0], const <E>[.answer]); | ||
Expect.identical(const [ET(42)], const <ET>[.answer]); | ||
} |
56 changes: 56 additions & 0 deletions
56
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t05.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,56 @@ | ||
// 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 to use a non-constant | ||
/// static member shorthand expression in a constant list literal. | ||
/// @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 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() { | ||
print(const <C>[.answer]); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
print(const <M>[.answer]); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
print(const <E>[.answer]); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
print(const <ET>[.answer]); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
46 changes: 46 additions & 0 deletions
46
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t06.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,46 @@ | ||
// 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 set literal. | ||
/// @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() { | ||
Expect.identical(const {C(42)}, const <C>{.answer}); | ||
Expect.identical(const <M>{MC(42)}, const <M>{.answer}); | ||
Expect.identical(const {E.e0}, const <E>{.answer}); | ||
Expect.identical(const {ET(42)}, const <ET>{.answer}); | ||
} |
56 changes: 56 additions & 0 deletions
56
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t07.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,56 @@ | ||
// 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 to use a non-constant | ||
/// static member shorthand expression in a constant set literal. | ||
/// @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 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() { | ||
print(const <C>{.answer}); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
print(const <M>{.answer}); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
print(const <E>{.answer}); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
print(const <ET>{.answer}); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
53 changes: 53 additions & 0 deletions
53
LanguageFeatures/Static-access-shorthand/constant_expression_A10_t08.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,53 @@ | ||
// 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 map literal. | ||
/// @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() { | ||
Expect.identical(const {"key": C(42)}, const <String, C>{"key": .answer}); | ||
Expect.identical( | ||
const <M, String>{MC(42): "value"}, | ||
const <M, String>{.answer: "value"}, | ||
); | ||
Expect.identical(const {"key": E.e0}, const <String, E>{"key": .answer}); | ||
Expect.identical( | ||
const {ET(42): "value"}, | ||
const <ET, String>{.answer: "value"}, | ||
); | ||
} |
Oops, something went wrong.