Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2638. Add extension methods test for type aliases #2640

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions LanguageFeatures/Extension-methods/syntax_name_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@
// 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:
/// @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. The name does not denote a type, but it can be used to denote the
/// extension itself in various places. The name can be hidden or shown in import
/// or export declarations.
/// extension itself in various places. The name can be hidden or shown in
/// import export declarations.
///
/// @description Check that the name does not denote a type
/// @author sgrekhov@unipro.ru



extension MyFancyList<T> on List<T> {
int get doubleLength => this.length * 2;
List<T> operator-() => this.reversed.toList();
List<List<T>> split(int at) => <List<T>>[this.sublist(0, at), this.sublist(at)];
static String get className => "List";
}
extension MyFancyList<T> on List<T> {}

main() {
MyFancyList<String> list = ["Lily", "was", "here"];
Expand Down
10 changes: 4 additions & 6 deletions LanguageFeatures/Extension-methods/syntax_name_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
// 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:
/// @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. The name does not denote a type, but it can be used to denote the
/// extension itself in various places. The name can be hidden or shown in import
/// or export declarations.
/// extension itself in various places. The name can be hidden or shown in
/// import export declarations.
///
/// @description Check that the name does not denote a type
/// @author sgrekhov@unipro.ru



import "my_fancy_list_lib.dart";

main() {
Expand Down
10 changes: 4 additions & 6 deletions LanguageFeatures/Extension-methods/syntax_name_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
// 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:
/// @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. The name does not denote a type, but it can be used to denote the
/// extension itself in various places. The name can be hidden or shown in import
/// or export declarations.
/// extension itself in various places. The name can be hidden or shown in
/// import export declarations.
///
/// @description Check that the name can be hidden or shown in import or export
/// declarations.
/// @author sgrekhov@unipro.ru



import "my_fancy_list_lib.dart" hide MyFancyList;

main() {
Expand Down
10 changes: 4 additions & 6 deletions LanguageFeatures/Extension-methods/syntax_name_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
// 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:
/// @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. The name does not denote a type, but it can be used to denote the
/// extension itself in various places. The name can be hidden or shown in import
/// or export declarations.
/// extension itself in various places. The name can be hidden or shown in
/// import export declarations.
///
/// @description Check that the name can be hidden or shown in import or export
/// declarations.
/// @author sgrekhov@unipro.ru



import "../../Utils/expect.dart";
import "my_fancy_list_lib.dart" show MyFancyList;

Expand Down
30 changes: 30 additions & 0 deletions LanguageFeatures/Extension-methods/syntax_name_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024, 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. The name does not denote a type, but it can be used to denote the
/// extension itself in various places. The name can be hidden or shown in
/// import export declarations.
///
/// @description Check that it is a compile-time error to create a type alias
/// for an extension
/// @author sgrekhov22@gmail.com

class A {}
extension Ext on A {}

typedef ExtAlias = Ext;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(A);
}