Skip to content

Commit

Permalink
#1400. Add tests for external members, covariant parameters, nullable…
Browse files Browse the repository at this point in the history
… supertypes (#2225)

Add tests for external members, covariant parameters, nullable supertypes. Note that A10_t02 and A12_t01 intentionally have a syntax error (a superinterface of the form `T?`).
  • Loading branch information
sgrekhov authored Aug 23, 2023
1 parent 4be0eaf commit a5c5d47
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ extension type ET4<T>(T id) {
// [cfe] unspecified
}

extension type ET5(int id) {
int operator +(int other);
//^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(ET1);
print(ET2);
print(ET3);
print(ET4);
print(ET5);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 It is not an error for an extension type member to have the
/// modifier external
///
/// @description Checks that it is not an error for an extension type member to
/// have the modifier `external`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

extension type ET1(int id) {
external int m;
}

extension type ET2<T>(T id) {
external T get getter;
}

extension type ET3(int id) {
external void setter(int x);
}

extension type ET4<T extends num>(T id) {
external void method();
}

extension type ET5(int id) {
external int operator +(int other);
}

main() {
print(ET1);
print(ET2);
print(ET3);
print(ET4);
print(ET5);
}
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 It is not an error for an extension type member to have the
/// modifier external
///
/// @description Checks that it is not an error for an extension type static
/// member to have the modifier `external`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

extension type ET1(int id) {
external static int m;
}

extension type ET2<T>(T id) {
external static T get getter;
}

extension type ET3(int id) {
external static void setter(int x);
}

extension type ET4<T extends num>(T id) {
external static void method();
}

main() {
print(ET1);
print(ET2);
print(ET3);
print(ET4);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 It is a compile-time error if the modifier covariant occurs in
/// the declaration of a formal parameter of a function which is not an instance
/// method, an instance setter, or an operator.
///
/// @description Checks that it is a compile-time error if an extension type
/// member has a member with a covariant formal parameter
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

extension type ET1(num id) {
void method(covariant int i) {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET2<T extends num>(T id) {
void setter(covariant int x) {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET3(num id) {
int operator +(covariant int other) => other + id.floor();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(ET1);
print(ET2);
print(ET3);
}
41 changes: 41 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A10_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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>
/// ...
/// There are no special rules for static members in extension types. They can
/// be declared and called or torn off as usual, e.g.,
/// AnExtensionType.myStaticMethod(42)
///
/// @description Checks that it is a compile-time error if an extension type
/// declares a static operator
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

extension type ET(int id) {
static int operator +(int other) => id + other;
//^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(ET);
}
55 changes: 55 additions & 0 deletions LanguageFeatures/Extension-types/syntax_A12_t01.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 a compile-time error if an extension type
/// has a nullable type as a superinterface
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

typedef NullableInt = int?;

extension type ET1(int id) implements int? {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET2(int? id) implements int? {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET3(int id) implements NullableInt {}
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET4(int? id) implements NullableInt {}
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(ET1);
print(ET2);
print(ET3);
print(ET4);
}

0 comments on commit a5c5d47

Please sign in to comment.