Skip to content

Commit

Permalink
Fixes #2339. Add tests that extension can't have name type (#2340)
Browse files Browse the repository at this point in the history
Add tests that extension can't have name `type`
  • Loading branch information
sgrekhov authored Nov 3, 2023
1 parent 1c4d468 commit 7ccb121
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LanguageFeatures/Extension-methods/syntax_t05.dart
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();
}
27 changes: 27 additions & 0 deletions LanguageFeatures/Extension-methods/syntax_t06.dart
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();
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A13_t01.dart
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);
}
59 changes: 59 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A13_t02.dart
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() {
}
60 changes: 60 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A13_t03.dart
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() {
}
55 changes: 55 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A13_t04.dart
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);
}

0 comments on commit 7ccb121

Please sign in to comment.