-
Notifications
You must be signed in to change notification settings - Fork 28
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
#1400. Add cascade invocation test and more constants tests #2545
Merged
eernstg
merged 1 commit into
dart-lang:master
from
sgrekhov:co19-1400-cascade-and-const
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! An instance constant doesn't exist, but we should check that it isn't magically brought into existence with an extension type.