-
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
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
LanguageFeatures/Extension-types/dynamic_semantics_extension_type_A05_t04.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,33 @@ | ||
// 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 Consider an extension type declaration DV named Name with | ||
/// representation name id and representation type R. Invocation of a | ||
/// non-redirecting generative extension type constructor proceeds as follows: | ||
/// A fresh, non-late, final variable v is created. An initializing formal | ||
/// this.id has the side-effect that it initializes v to the actual argument | ||
/// passed to this formal. An initializer list element of the form id = e or | ||
/// this.id = e is evaluated by evaluating e to an object o and binding v to o. | ||
/// During the execution of the constructor body, this and id are bound to the | ||
/// value of v. The value of the instance creation expression that gave rise to | ||
/// this constructor execution is the value of this. | ||
/// | ||
/// @description Check evaluation of an initializer list with a cascade | ||
/// expressions | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
extension type ET1(List<int> id) { | ||
ET1.pair(int v1, int v2) : this.id = [] | ||
..add(v1) | ||
..add(v2); | ||
} | ||
|
||
main() { | ||
var et = ET1.pair(1, 2); | ||
Expect.listEquals([1, 2], 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,42 @@ | ||
// 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> | ||
/// ... | ||
/// Some errors can be detected immediately from the syntax: | ||
/// | ||
/// A compile-time error occurs if the extension type declaration declares any | ||
/// instance variables, unless they are external | ||
/// | ||
/// @description Checks that it is a compile-time error if an extension type | ||
/// declaration declares a non-static constant. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension type ET(int _) { | ||
const int x = 0; | ||
//^^^^^ | ||
// [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,51 @@ | ||
// 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 extension types may have static final and constant | ||
/// members. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension type ET1(int id) { | ||
static final int answer = 42; | ||
static const zero = 0; | ||
|
||
const ET1.named() : id = zero; | ||
} | ||
|
||
extension type ET2(List<int> id) { | ||
const ET2.named() : id = const [ET1.zero]; | ||
} | ||
|
||
main() { | ||
Expect.equals(42, ET1.answer); | ||
Expect.identical(0, ET1.zero); | ||
Expect.listEquals([0], ET2.named().id); | ||
Expect.identical(const [0], const ET2.named().id); | ||
Expect.identical(const [0], ET2.named().id); | ||
} |