-
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. [Views] Syntax tests added #1498
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8f24016
#1400. [Views] Syntax tests added
sgrekhov c356b75
#1400. [Views] More syntax tests added
sgrekhov 41ca129
Apply suggestions from code review
sgrekhov 5cf9b62
#1400. [Views] Syntax tests updated according to the review notes
sgrekhov 9bb1e56
#1400. [Views] Missing newlines at the end added
sgrekhov 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
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,37 @@ | ||
// Copyright (c) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// The token `view` is made a built-in identifier. | ||
/// | ||
/// @description Checks that it is a compile-time error to declare a class | ||
/// named `view` | ||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
class view { | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
view(); | ||
} |
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,39 @@ | ||
// Copyright (c) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// The token `view` is made a built-in identifier. | ||
/// | ||
/// @description Checks that it is a compile-time error to declare a mixin | ||
/// named `view` | ||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
mixin view on Object { | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class VA = Object with view; | ||
|
||
main() { | ||
VA(); | ||
} |
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,36 @@ | ||
// Copyright (c) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// The token `view` is made a built-in identifier. | ||
/// | ||
/// @description Checks that it is a compile-time error import a library with | ||
/// import prefix `view` | ||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
import "views_lib.dart" as view; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
view.x; | ||
} |
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,36 @@ | ||
// Copyright (c) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// The token `view` is made a built-in identifier. | ||
/// | ||
/// @description Checks that it is a compile-time error to declare a type alias | ||
/// named `view` | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
typedef view = String; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
view s = ""; | ||
} |
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,67 @@ | ||
// Copyright (c) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// ... | ||
/// If a view declaration named View includes a <viewPrimaryConstructor> then it | ||
/// is a compile-time error if the declaration includes a constructor | ||
/// declaration named View. (But it can still contain other constructors.) | ||
/// | ||
/// @description Checks that it is a compile-time error if a view declaration | ||
/// named `View` includes a <viewPrimaryConstructor> and includes a constructor | ||
/// named `View` | ||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
view class View1(int id) { | ||
View1(this.id); | ||
//^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View2(int id) { | ||
View2(int id, int x) {} | ||
//^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View3(int id) { | ||
View3(); | ||
//^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View4(int id) { | ||
factory View4(int id) => View4.named(id); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
View4.named(int x) : id = x; | ||
} | ||
|
||
main() { | ||
print(View1); | ||
print(View2); | ||
print(View3); | ||
print(View4); | ||
} |
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,62 @@ | ||
// Copyright (c) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// ... | ||
/// If a view declaration named View includes a <viewPrimaryConstructor> then it | ||
/// is a compile-time error if the declaration includes a constructor | ||
/// declaration named View. (But it can still contain other constructors.) | ||
/// | ||
/// @description Checks that it is a compile-time error if a view declaration | ||
/// named `View` includes a <viewPrimaryConstructor> with zero or more than one | ||
/// parameters | ||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
view class View1() { | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View2(int id, String name) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View3(int id, {String name}) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View4(int id, [String name]) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(View1); | ||
print(View2); | ||
print(View3); | ||
print(View4); | ||
} |
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) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// ... | ||
/// If a view declaration named View includes a <viewPrimaryConstructor> then it | ||
/// is a compile-time error if the declaration includes a constructor | ||
/// declaration named View. (But it can still contain other constructors.) | ||
/// | ||
/// @description Checks that it is a compile-time error if a view declaration | ||
/// named `View` includes a <viewPrimaryConstructor> with named or optional | ||
/// positional parameter | ||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
view class View1({int id}) { | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View2({required int id}) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
view class View3([int id]) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(View1); | ||
print(View2); | ||
print(View3); | ||
} |
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,46 @@ | ||
// Copyright (c) 2022, 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 <viewDeclaration> is added to the grammar, along with | ||
/// some rules for elements used in view declarations: | ||
/// | ||
/// <viewDeclaration> ::= | ||
/// 'view' 'class' <typeIdentifier> <typeParameters>? | ||
/// <viewPrimaryConstructor>? | ||
/// <interfaces>? | ||
/// '{' | ||
/// (<metadata> <viewMemberDeclaration>)* | ||
/// '}' | ||
/// | ||
/// <viewPrimaryConstructor> ::= | ||
/// '(' <type> <identifier> ')' | ||
/// | ||
/// <viewMemberDeclaration> ::= | ||
/// <classMemberDefinition> | ||
/// ... | ||
/// If a view declaration named View includes a <viewPrimaryConstructor> then it | ||
/// is a compile-time error if the declaration includes a constructor | ||
/// declaration named View. (But it can still contain other constructors.) | ||
/// | ||
/// @description Checks that if a view declaration named `View` includes a | ||
/// <viewPrimaryConstructor> then it can contain other (than named `View`) | ||
/// constructors | ||
/// | ||
/// @author sgrekhov22@gmail.com | ||
|
||
// SharedOptions=--enable-experiment=extension-types | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
view class View(int id) { | ||
View.c1(int x, int y) : id = x + y; | ||
View.c2(int x) : id = x; | ||
View.c3() : id = 0; | ||
} | ||
|
||
main() { | ||
Expect.equals(3, View.c1(1, 2).id); | ||
Expect.equals(4, View.c2(4).id); | ||
Expect.equals(0, View.c3().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.
No, that would actually not be an error. I've specified that
view
is a built-in identifier, which means that it would be an error to declare a type with that name, but other things (a function, a local variable, etc, anything-not-an-type) would be ok.