-
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.
#1400. Add tests for external members, covariant parameters, nullable…
… 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
Showing
6 changed files
with
219 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
40 changes: 40 additions & 0 deletions
40
LanguageFeatures/Extension-types/static_analysis_extension_types_A28_t01.dart
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,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); | ||
} |
35 changes: 35 additions & 0 deletions
35
LanguageFeatures/Extension-types/static_analysis_extension_types_A28_t02.dart
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 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); | ||
} |
40 changes: 40 additions & 0 deletions
40
LanguageFeatures/Extension-types/static_analysis_extension_types_A29_t01.dart
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,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); | ||
} |
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,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); | ||
} |
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 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); | ||
} |