diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A05_t01.dart b/LanguageFeatures/Static-access-shorthand/grammar_A05_t01.dart new file mode 100644 index 0000000000..51f01da22a --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A05_t01.dart @@ -0,0 +1,145 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax with the prefix `!` operator. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static bool get getterTrue => true; + static bool methodTrue() => true; + static List values = [true]; +} + +mixin M on C { + static bool get getterTrue => true; + static bool methodTrue() => true; + static List values = [true]; +} +class MC = C with M; + +enum E { + e1; + + static bool get getterTrue => true; + static bool methodTrue() => true; + static List boolValues = [true]; +} + +extension type ET(int v) implements int { + static bool get getterTrue => true; + static bool methodTrue() => true; + static List values = [true]; +} + +main() { + Object o = C(); + if (o is C) { + o = !.getterTrue; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = !.methodTrue(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = !.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = !.getterTrue; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = !.methodTrue(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = !.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = !.getterTrue; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = !.methodTrue(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = !.boolValues[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = !.getterTrue; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = !.methodTrue(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = !.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A05_t02.dart b/LanguageFeatures/Static-access-shorthand/grammar_A05_t02.dart new file mode 100644 index 0000000000..672e2d9f30 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A05_t02.dart @@ -0,0 +1,145 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax with the unary `-` operator. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +mixin M on C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} +class MC = C with M; + +enum E { + e1; + + static int get one => 1; + static int two() => 2; + static List intValues = [1]; +} + +extension type ET(int v) implements int { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +main() { + Object o = C(); + if (o is C) { + o = -.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = -.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = -.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = -.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = -.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = -.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = -.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = -.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = -.intValues[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = -.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = -.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = -.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A05_t03.dart b/LanguageFeatures/Static-access-shorthand/grammar_A05_t03.dart new file mode 100644 index 0000000000..89c71093cd --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A05_t03.dart @@ -0,0 +1,145 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax with the `~` operator. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +mixin M on C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} +class MC = C with M; + +enum E { + e1; + + static int get one => 1; + static int two() => 2; + static List intValues = [1]; +} + +extension type ET(int v) implements int { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +main() { + Object o = C(); + if (o is C) { + o = ~.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = ~.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = ~.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = ~.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = ~.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = ~.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = ~.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = ~.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = ~.intValues[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = ~.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = ~.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = ~.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A05_t04.dart b/LanguageFeatures/Static-access-shorthand/grammar_A05_t04.dart new file mode 100644 index 0000000000..2bf07fbef4 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A05_t04.dart @@ -0,0 +1,145 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax with the prefix `++` operator. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +mixin M on C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} +class MC = C with M; + +enum E { + e1; + + static int get one => 1; + static int two() => 2; + static List intValues = [1]; +} + +extension type ET(int v) implements int { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +main() { + Object o = C(); + if (o is C) { + o = ++.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = ++.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = ++.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = ++.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = ++.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = ++.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = ++.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = ++.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = ++.intValues[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = ++.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = ++.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = ++.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A05_t05.dart b/LanguageFeatures/Static-access-shorthand/grammar_A05_t05.dart new file mode 100644 index 0000000000..9a0d7c215d --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A05_t05.dart @@ -0,0 +1,145 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax with the prefix `--` operator. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +mixin M on C { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} +class MC = C with M; + +enum E { + e1; + + static int get one => 1; + static int two() => 2; + static List intValues = [1]; +} + +extension type ET(int v) implements int { + static int get one => 1; + static int two() => 2; + static List values = [1]; +} + +main() { + Object o = C(); + if (o is C) { + o = --.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = --.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = --.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = --.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = --.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = --.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = --.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = --.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = --.intValues[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = --.one; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = --.two(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = --.values[0]; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A06_t01.dart b/LanguageFeatures/Static-access-shorthand/grammar_A06_t01.dart new file mode 100644 index 0000000000..9fa41d2c42 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A06_t01.dart @@ -0,0 +1,113 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax with the postfix `++` operator. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static int value = 1; + static List values = [1]; +} + +mixin M on C { + static int value = 1; + static List values = [1]; +} +class MC = C with M; + +enum E { + e1; + + static int value = 1; + static List intValues = [1]; +} + +extension type ET(int v) implements int { + static int value = 1; + static List values = [1]; +} + +main() { + Object o = C(); + if (o is C) { + o = .value++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = .values[0]++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = .value++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = .values[0]++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = .value++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = .intValues[0]++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = .value++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = .values[0]++; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A06_t02.dart b/LanguageFeatures/Static-access-shorthand/grammar_A06_t02.dart new file mode 100644 index 0000000000..afb233cd18 --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A06_t02.dart @@ -0,0 +1,113 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax with the postfix `--` operator. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static int value = 1; + static List values = [1]; +} + +mixin M on C { + static int value = 1; + static List values = [1]; +} +class MC = C with M; + +enum E { + e1; + + static int value = 1; + static List intValues = [1]; +} + +extension type ET(int v) implements int { + static int value = 1; + static List values = [1]; +} + +main() { + Object o = C(); + if (o is C) { + o = .value--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = .values[0]--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = .value--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = .values[0]--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = .value--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = .intValues[0]--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = .value--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = .values[0]--; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A07_t01.dart b/LanguageFeatures/Static-access-shorthand/grammar_A07_t01.dart new file mode 100644 index 0000000000..9c41a5303c --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A07_t01.dart @@ -0,0 +1,141 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax in string literals. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +class C { + static String one = "one"; + static String two() => "two"; +} + +mixin M on C { + static String one = "one"; + static String two() => "two"; +} +class MC = C with M; + +enum E { + e1; + + static String one = "one"; + static String two() => "two"; +} + +extension type ET(int v) implements int { + static String one = "one"; + static String two() => "two"; +} + +main() { + Object o = C(); + if (o is C) { + o = "$.one"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = "${.one}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = C(); + if (o is C) { // ignore: unnecessary_type_check + o = "${.two()}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = MC(); + if (o is M) { + o = "${.one}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = "${.one}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = MC(); + if (o is M) { // ignore: unnecessary_type_check + o = "${.two()}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = E.e1; + if (o is E) { + o = "$.one"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = "${.one}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = E.e1; + if (o is E) { // ignore: unnecessary_type_check + o = "${.two()}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + + o = ET(0); + if (o is ET) { + o = "$.one"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = "${.one}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + o = ET(0); + if (o is ET) { // ignore: unnecessary_type_check + o = "${.two()}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} diff --git a/LanguageFeatures/Static-access-shorthand/grammar_A07_t02.dart b/LanguageFeatures/Static-access-shorthand/grammar_A07_t02.dart new file mode 100644 index 0000000000..d2765aa24f --- /dev/null +++ b/LanguageFeatures/Static-access-shorthand/grammar_A07_t02.dart @@ -0,0 +1,40 @@ +// 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 We introduce grammar productions of the form: +/// ``` +/// ::= ... -- all current productions +/// | -- added production +/// +/// ::= ... -- all current productions +/// | -- No selectors, no `.new`. +/// +/// ::= * +/// +/// ::= +/// +/// | '.' 'new' -- shorthand unnamed constructor +/// +/// ::= -- something that can potentially create a value. +/// | '.' -- shorthand for qualified name +/// | 'const' '.' ( | 'new') -- shorthand for constant object creation +/// ``` +/// +/// @description Checks that it is a compile-time error to use the static access +/// shorthand syntax in string literals. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=enum-shorthands + +main() { + String s = "${.fromCharCode(100)}"; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + print("${.fromCharCodes([100, 101])}"); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +}