-
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.
Add syntax tests for extension type declarations.
- Loading branch information
Showing
22 changed files
with
890 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
/// @description Helper library for testing extension types | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
library extension_type_lib; | ||
|
||
int x = 42; | ||
|
||
extension type _PrivateExtensionType(int id) { | ||
} |
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,36 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// The token `type` is not made a built-in identifier: the built-in identifier | ||
/// extension that occurs right before type serves to disambiguate the extension | ||
/// type declaration with a fixed lookahead. | ||
/// | ||
/// @description Checks that it is not an error to declare a class named `type` | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
class type { | ||
} | ||
|
||
main() { | ||
type(); | ||
} |
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,38 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// The token `type` is not made a built-in identifier: the built-in identifier | ||
/// extension that occurs right before type serves to disambiguate the extension | ||
/// type declaration with a fixed lookahead. | ||
/// | ||
/// @description Checks that it is not an error to declare a mixin named `type` | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
mixin type on Object { | ||
} | ||
|
||
class IA = Object with type; | ||
|
||
main() { | ||
IA(); | ||
} |
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,36 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// The token `type` is not made a built-in identifier: the built-in identifier | ||
/// extension that occurs right before type serves to disambiguate the extension | ||
/// type declaration with a fixed lookahead. | ||
/// | ||
/// @description Checks that it is not an error to import a library with | ||
/// import prefix `type` | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "extension_type_lib.dart" as type; | ||
|
||
main() { | ||
print(type.x); | ||
} |
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,37 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// The token `type` is not made a built-in identifier: the built-in identifier | ||
/// extension that occurs right before type serves to disambiguate the extension | ||
/// type declaration with a fixed lookahead. | ||
/// | ||
/// @description Checks that it is not an error to declare a type alias named | ||
/// `type` | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
typedef type = String; | ||
|
||
main() { | ||
type s = "type"; | ||
s.substring(1); | ||
} |
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,36 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// @description Checks that it is a compile-time error if an extension type | ||
/// declaration doesn't contain `typeIdentifier` | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type (int id) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
|
||
} |
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,34 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// @description Checks that it is a compile-time error to refer an extension | ||
/// type with the `typeIdentifier` started with `_` outside of the library where | ||
/// it is defined | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
main() { | ||
print(_PrivateExtensionType); | ||
// ^^^^^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
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,38 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// @description Checks that an extension type declaration may have type | ||
/// parameters | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension type ET<T>(T id) {} | ||
|
||
main() { | ||
ET<int> et1 = ET<int>(42); | ||
Expect.equals(42, et1.id); | ||
|
||
ET<String> et2 = ET<String>.new("42"); | ||
Expect.equals("42", et2.id); | ||
} |
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,36 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// @description Checks that it is a compile-time error if an extension type | ||
/// declaration doesn't contain `representationDeclaration` | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type ET { | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(ET); | ||
} |
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) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// @description Checks that a `representationDeclaration` may have form | ||
/// `identifier`.`identifier`... | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension type ET.et(int id) {} | ||
|
||
main() { | ||
ET et = ET.et(42); | ||
Expect.equals(42, et.id); | ||
} |
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,38 @@ | ||
// Copyright (c) 2023, 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 rule for <extensionTypeDeclaration> is added to the grammar, | ||
/// along with some rules for elements used in extension type declarations: | ||
/// | ||
/// <extensionTypeDeclaration> ::= | ||
/// 'extension' 'type' 'const'? <typeIdentifier> <typeParameters>? | ||
/// <representationDeclaration> <interfaces>? | ||
/// '{' | ||
/// (<metadata> <extensionTypeMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <representationDeclaration> ::= | ||
/// ('.' <identifierOrNew>)? '(' <metadata> <type> <identifier> ')' | ||
/// | ||
/// <identifierOrNew> ::= <identifier> | 'new' | ||
/// | ||
/// <extensionTypeMemberDeclaration> ::= <classMemberDefinition> | ||
/// | ||
/// @description Checks that a `representationDeclaration` may have form | ||
/// `identifier`.new | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension type ET.new(int id) {} | ||
|
||
main() { | ||
ET et1 = ET(1); | ||
Expect.equals(1, et1.id); | ||
|
||
ET et2 = ET.new(2); | ||
Expect.equals(2, et2.id); | ||
} |
Oops, something went wrong.