-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Function
is a built-in identifier, but no error is emitted when it is used to name a type
#45703
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
Comments
The link tries to point to line 16025 in a file with 14154 lines in it... Could you provide a better link? |
The link is correct, but Github sometimes doesn't show the whole file (it's 21899 lines). Try reloading. |
Hah, fantastic! Thanks! |
There is class |
As I remember it (big caveat), we did not choose to make One of the reasons was that |
Section 17.37 Identifier Reference, as of May 6, lists |
Nope, my bad. In which case the platform "class" declaration for |
Yes, We do get an error for a type alias, for the CFE as well as the analyzer: // Store in `n014.dart`.
typedef Function = int;
void main() {}
/*
> dart n014.dart
n014.dart:1:9: Error: 'Function' can't be used as an identifier because it's a keyword.
Try renaming this to be an identifier that isn't a keyword.
typedef Function = int;
^^^^^^^^
> dartanalyzer n014.dart
Analyzing n014.dart...
error • 'Function' can't be used as an identifier because it's a keyword. • n014.dart:1:9 • expected_identifier_but_got_keyword
1 error found.
*/ We do not get that error for a class or a mixin, but the analyzer reports that it is "deprecated" to use the name So do we wish to make it a regular identifier in the spec, given that the error is not emitted for classes an mixins? I don't think it will create any serious parsing difficulties because |
I'll just note that there is a CL to start generating diagnostics in analyzer in these cases (https://dart-review.googlesource.com/c/sdk/+/195760). Does the fact that we use |
I started this in https://dart-review.googlesource.com/c/sdk/+/200080, but it seems that there are more changes to CFE than I can do on my own. |
No, when followed by |
I see that we issue a hint on this now, but we also seem to issue the hint for the version that is in the SDK core libraries (which, from conversation above, is supposed to be exempt?). |
Yes, we're producing a hint for class declarations (
@stereotype441 In case you'd be interested in fixing this, given that it spans both analyzer and CFE. |
This CL makes `Function` a builtIn keyword instead of a `pseudo` keyword. See also (and fixes): #45703 #45704 #45705 #49197 This undoes https://dart-review.googlesource.com/c/sdk/+/195761 This is ~a merge of https://dart-review.googlesource.com/c/sdk/+/195906 and https://dart-review.googlesource.com/c/sdk/+/200080 Change-Id: I8bfee6976d43819fa355de99b3b2429eb67a7cdd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249484 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
This should be fixed with 25dcfca. |
Consider the following programs:
The word
Function
is a built-in identifier, but it is not consistently reported as an error when this word is used as the name of a type (that is, a class, type parameter, type alias, etc.).No errors or other diagnostics are emitted except for the following:
Function
is deprecated.typedef Function = int;
.All declaring occurrences of
Function
should be marked as a compile-time error.The text was updated successfully, but these errors were encountered: