-
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.
Browse files
Browse the repository at this point in the history
Add tests that extension can't have name `type`
- Loading branch information
Showing
6 changed files
with
265 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,27 @@ | ||
// 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 an extension declaration is a top-level declaration with a grammar | ||
/// similar to: | ||
/// <extension> ::= | ||
/// `extension' <identifier>? <typeParameters>? `on' <type> `?'? `{' | ||
/// memberDeclaration* | ||
/// `}' | ||
/// Such a declaration introduces its name (the identifier) into the surrounding | ||
/// scope | ||
/// | ||
/// @description Check that it is a compile-time error if an extension has the | ||
/// name `type` | ||
/// @author sgrekhov22@gmail.com | ||
class C {} | ||
|
||
extension type on C {} | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
C(); | ||
} |
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,27 @@ | ||
// 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 an extension declaration is a top-level declaration with a grammar | ||
/// similar to: | ||
/// <extension> ::= | ||
/// `extension' <identifier>? <typeParameters>? `on' <type> `?'? `{' | ||
/// memberDeclaration* | ||
/// `}' | ||
/// Such a declaration introduces its name (the identifier) into the surrounding | ||
/// scope | ||
/// | ||
/// @description Check that it is a compile-time error if an extension has the | ||
/// name `type` | ||
/// @author sgrekhov22@gmail.com | ||
class C<T> {} | ||
|
||
extension type<T> on C<T> {} | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
C(); | ||
} |
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> | ||
/// | ||
/// @description Checks that it is not an error if an extension type has the | ||
/// name `type` or 'on' | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension type type(int id) {} | ||
|
||
extension type on(int id) {} | ||
|
||
main() { | ||
Expect.equals(42, type(42).id); | ||
Expect.equals(42, on(42).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,59 @@ | ||
// 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 | ||
/// has the name which is a reserved word | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type assert(int id) {} | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type class(int id) {} | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type extends(int id) {} | ||
// ^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type if(int id) {} | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type new(int id) {} | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type with(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,60 @@ | ||
// 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 | ||
/// has the name which is a built-in identifier | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 53930 | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type abstract(int id) {} | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type extension(int id) {} | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type factory(int id) {} | ||
// ^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type import(int id) {} | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type required(int id) {} | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
extension type typedef(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,55 @@ | ||
// 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 not an error if an extension type has the | ||
/// name which is OTHER_IDENTIFIER_NOT_TYPE | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension type async(int id) {} | ||
|
||
extension type hide(int id) {} | ||
|
||
extension type of(int id) {} | ||
|
||
extension type on(int id) {} | ||
|
||
extension type show(int id) {} | ||
|
||
extension type sync(int id) {} | ||
|
||
extension type await(int id) {} | ||
|
||
extension type yield(int id) {} | ||
|
||
main() { | ||
Expect.equals(42, async(42).id); | ||
Expect.equals(42, hide(42).id); | ||
Expect.equals(42, of(42).id); | ||
Expect.equals(42, on(42).id); | ||
Expect.equals(42, show(42).id); | ||
Expect.equals(42, sync(42).id); | ||
Expect.equals(42, await(42).id); | ||
Expect.equals(42, yield(42).id); | ||
} |