-
Notifications
You must be signed in to change notification settings - Fork 28
Fix #2485. Updateas
and is
expressions tests with a function type
#2538
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
Merged
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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
84 changes: 84 additions & 0 deletions
84
LanguageFeatures/Constructor-tear-offs/ambiguities_A36_t04.dart
This file contains hidden or 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,84 @@ | ||
// Copyright (c) 2024, 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 This new syntax also introduces new ambiguities in the grammar, | ||
/// similar to the one we introduced with generic functions. Examples include: | ||
/// | ||
/// f(a<b,c>(d)); // Existing ambiguity, resolved to a generic method call. | ||
/// f(x.a<b,c>[d]); // f((x.a<b, c>)[d]) or f((x.a < b), (c > [d])) | ||
/// f(x.a<b,c>-d); // f((x.a<b, c>)-d) or f((x.a < b), (c > -d])) | ||
/// The x.a<b,c> can be an explicitly instantiated generic function tear-off or | ||
/// an explicitly instantiated type literal named using a prefix, which is new. | ||
/// While neither type objects nor functions declare operator- or operator[], | ||
/// such could be added using extension methods. | ||
/// | ||
/// We will disambiguate such situations heuristically based on the token | ||
/// following the > that matches the < we are ambiguous about. In the existing | ||
/// ambiguity we treat ( as a sign that the < starts a generic invocation. We | ||
/// extend the number of tokens which, when following a potential type argument | ||
/// list, makes us choose to parse the previous tokens as that type argument | ||
/// list. | ||
/// | ||
/// There is a number of tokens which very consistently end an expression, and | ||
/// we include all those: | ||
/// | ||
/// ), }, ], ;, :, , | ||
/// | ||
/// Then we include tokens which we predict will continue a generic instantiation: | ||
/// | ||
/// ( . == != | ||
/// | ||
/// The first six are tokens which cannot possibly start an expression, and | ||
/// therefore cannot occur after a greater-than infix operator. The last four | ||
/// tokens can continue an expression, and of those only ( can also start an | ||
/// expression, and we already decided how to disambiguate that). | ||
/// | ||
/// There are many other tokens which currently cannot continue an expression | ||
/// (and therefore cannot validly follow a type argument list) or which cannot | ||
/// start an expression (and therefore cannot validly follow a greater-than | ||
/// operator), but in the service of keeping our future options open, we choose | ||
/// a design that does not rely on those restrictions. For example we omit most | ||
/// infix operators from being "continuation tokens", even though they currently | ||
/// cannot start a new expression, and therefore cannot follow a > infix | ||
/// operator. This leaves us open to allowing some of those operators as prefix | ||
/// operators in the future, like we currently allow the - operator. | ||
/// | ||
/// @description Checks that it is a syntax error if function with type argument | ||
/// specified is part of `as`, `as!` or `is` expressions | ||
/// @author [email protected] | ||
|
||
int bar<T>(T t) => 42; | ||
void foo<T1, T2, T3>() {} | ||
|
||
main() { | ||
const c1 = bar<int> as int Function(int); | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const c2 = bar<int> is! int Function(int); | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const c3 = bar<int> is int Function(int); | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const c4 = foo<int, String, bool> as void Function(); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const c5 = foo<int, String, bool> is! void Function(); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
const c6 = foo<int, String, bool> is void Function(); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.