-
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.
#2976. Add more tests for records, factories and parenthesized expres…
…sions (#3047) Add more tests for records, factories and parenthesized expressions
- Loading branch information
Showing
6 changed files
with
223 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
64 changes: 64 additions & 0 deletions
64
LanguageFeatures/Static-access-shorthand/grammar_A01_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,64 @@ | ||
// 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: | ||
/// ``` | ||
/// <postfixExpression> ::= ... -- all current productions | ||
/// | <staticMemberShorthand> -- added production | ||
/// | ||
/// <constantPattern> ::= ... -- all current productions | ||
/// | <staticMemberShorthandValue> -- No selectors, no `.new`. | ||
/// | ||
/// <staticMemberShorthand> ::= <staticMemberShorthandHead> <selector>* | ||
/// | ||
/// <staticMemberShorthandHead> ::= | ||
/// <staticMemberShorthandValue> | ||
/// | '.' 'new' -- shorthand unnamed constructor | ||
/// | ||
/// <staticMemberShorthandValue> ::= -- something that can potentially create a value. | ||
/// | '.' <identifier> -- shorthand for qualified name | ||
/// | 'const' '.' (<identifier> | 'new') <arguments> -- shorthand for constant object creation | ||
/// ``` | ||
/// | ||
/// @description Checks that expressions of the form | ||
/// `const '(' '.' id(arguments) ',' ')'` and | ||
/// `const '(' '.' new(arguments) ',' ')'` are records containing constant | ||
/// shorthand expressions. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class C { | ||
final String value; | ||
const C(this.value); | ||
const C.id(this.value); | ||
const factory C.f(String value) = C; | ||
} | ||
|
||
extension type const ET(String value) { | ||
const ET.id(this.value); | ||
const factory ET.f(String value) = ET; | ||
} | ||
|
||
main() { | ||
const (C,) c1 = const (.new("one"),); | ||
Expect.equals("one", c1.$1.value); | ||
|
||
const (C,) c2 = const (.id("two"),); | ||
Expect.equals("two", c2.$1.value); | ||
|
||
const (C,) c3 = const (.f("three"),); | ||
Expect.equals("three", c3.$1.value); | ||
|
||
const (ET,) et1 = const (.new("new"),); | ||
Expect.equals("new", et1.$1.value); | ||
|
||
const (ET,) et2 = const (.id("id"),); | ||
Expect.equals("id", et2.$1.value); | ||
|
||
const (ET,) et3 = const (.f("f"),); | ||
Expect.equals("f", et3.$1.value); | ||
} |
70 changes: 70 additions & 0 deletions
70
LanguageFeatures/Static-access-shorthand/grammar_A01_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,70 @@ | ||
// 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: | ||
/// ``` | ||
/// <postfixExpression> ::= ... -- all current productions | ||
/// | <staticMemberShorthand> -- added production | ||
/// | ||
/// <constantPattern> ::= ... -- all current productions | ||
/// | <staticMemberShorthandValue> -- No selectors, no `.new`. | ||
/// | ||
/// <staticMemberShorthand> ::= <staticMemberShorthandHead> <selector>* | ||
/// | ||
/// <staticMemberShorthandHead> ::= | ||
/// <staticMemberShorthandValue> | ||
/// | '.' 'new' -- shorthand unnamed constructor | ||
/// | ||
/// <staticMemberShorthandValue> ::= -- something that can potentially create a value. | ||
/// | '.' <identifier> -- shorthand for qualified name | ||
/// | 'const' '.' (<identifier> | 'new') <arguments> -- shorthand for constant object creation | ||
/// ``` | ||
/// | ||
/// @description Checks that expressions of the form | ||
/// `const '(' '.' id(arguments) ')'` and | ||
/// `const '(' '.' new(arguments) ')'` are still compile-time errors. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
class C { | ||
final String value; | ||
const C(this.value); | ||
const C.id(this.value); | ||
const factory C.f(String value) = C; | ||
} | ||
|
||
extension type const ET(String value) { | ||
const ET.id(this.value); | ||
const factory ET.f(String value) = ET; | ||
} | ||
|
||
main() { | ||
const C c1 = const (.new("one")); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const C c2 = const (.id("two")); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const C c3 = const (.f("three")); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const ET et1 = const (.new("new")); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
const ET et2 = const (.id("id")); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const ET et3 = const (.f("f")); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |