-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Error in Dart spec 6.1 Function Declarations #515
Comments
This comment was originally written by [email protected] Added Area-Language, Triaged labels. |
This comment was originally written by [email protected] Please note that there is a typo in the spec: A function declaration of the form |
Resolved the typo in 0.08 draft. |
Added this to the M1 milestone. |
FWIW, final top level/static variables no longer need to be constant so that issue is not a concern. We are reviewing a series of bugs and issues relating to function declarations and will resolve this bug in that context. |
Added Done label. |
This issue was originally filed by [email protected]
The Draft Version 0.05, 6.1 Function Declarations reads:
A function declaration of the form
T0 id(T1 a1 , . . . , Tn an , [Tn+1 xn+1 = d1 , . . . , Tn+k xn+k = dk ){s}
is equivalent to a variable declaration of the form
final F id = (T1 a1 , . . . , Tn an , [Tn+1 xn+1 = d1 , . . . , Tn+k xn+k = dk ]){s},
where F is the function type alias (13.3.1)
typedef T0 F (T1 a1 , . . . , Tn an , [Tn+1 xn+1 , . . . , Tn+k xn+k ]).
Actually, this forms are not equivalent: first form can be placed anywhere, but second only as a local variable. Placing the second form at isolate or class level causes compile error: "initializer must be a compile time constant".
This is because a function literal is not a compile time constant (10.1 Constants). This is not in line with the fact that a "constant constructor invocation" is a compile time constant, so if a programmer really needs a function to be a compile-time constant, he/she can implement it as a method wrapped in a class constant. So the proposal is to list function literal as a compile time constant, and leave 6.1 Function Declarations intact.
The text was updated successfully, but these errors were encountered: