diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t12.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t12.dart new file mode 100644 index 0000000000..2845434c54 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t12.dart @@ -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 sgrekhov22@gmail.com + +// 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); +} diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t13.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t13.dart new file mode 100644 index 0000000000..28fa8fa278 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t13.dart @@ -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 sgrekhov22@gmail.com + +// 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 +} diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t14.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t14.dart new file mode 100644 index 0000000000..c64a7e2286 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t14.dart @@ -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 sgrekhov22@gmail.com + +// 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); +} diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t15.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t15.dart new file mode 100644 index 0000000000..0b75bc6204 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t15.dart @@ -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 sgrekhov22@gmail.com + +// 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 +} diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t16.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t16.dart new file mode 100644 index 0000000000..bccd7c1035 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t16.dart @@ -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 sgrekhov22@gmail.com + +// 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); +} diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t17.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t17.dart new file mode 100644 index 0000000000..e88053745e --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t17.dart @@ -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 sgrekhov22@gmail.com + +// 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 +} diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t18.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t18.dart new file mode 100644 index 0000000000..1528be39d3 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t18.dart @@ -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 sgrekhov22@gmail.com + +// 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); +} diff --git a/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t19.dart b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t19.dart new file mode 100644 index 0000000000..5e4c4875df --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/constant_expression_A10_t19.dart @@ -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` expression. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static C one = const C(1); + static const C? two = null; + final int v; + const C(this.v); +} + +mixin M on C { + static 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 E? two = null; +} + +extension type const ET(int v) { + static const ET one = const ET(1); + static ET? two = null; +} + +main() { + const C c = .two ?? .one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + const M m = .two ?? .one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + const E e = .two ?? .one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + const ET et = .two ?? .one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +}