-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[analyzer] Missing error for generic function instantiation on function object #46590
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
Thanks for the report, @eernstg . I'm trying to figure out from the spec what the error condition is.
Since, as you say, idVar does not denote a declaration of a local function, a static method, or a toplevel function, then we are not in this situation, and the mentioned compile-time error does not occur. |
Only the following short list of elements are allowed to be type- instantiated: top-level function, local function, instance method, constructor, type. Bug: #46233 and Change-Id: I37e2a793b7fb25ef670152490e73b227b7c0cdac #46590 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207643 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
The error condition is that When we operate on a local function, a static method, or a toplevel function, we get a compile-time error unless generic function type instantiation succeeds. (That is, in that particular situation we get a second chance, even though there is a type mismatch: We might be able to "repair" the type mismatch using a generic instantiation). |
I'm afraid this rule is getting reversed: The language team queried the CFE and backend teams about the need to have the restriction that "we can't perform a generic instantiation on an existing function object" (we've had this rule in the specification for years, but implementations did not enforce it consistently). It turns out to be unnecessary, so we are working on removing that restriction. Cf. dart-lang/language#1812. I think this is a useful change, we're removing a limitation which was conceptually unjustified (surprising, and based on implementation considerations), and now those implementation considerations turn out to be irrelevant after all. So we might as well just remove the limitation. So I'll close this issue. |
Consider the following program:
The initialization of
g
is a compile-time error, becauseidVar
is a variable and not a function declaration. However, the analyzer (as of commit ffde158) does not report any errors for this program.With
--enable-experiment=constructor-tearoff
we should get an error at the explicit instantiationidVar<int>
as well, and that error is also missing. Note that this question was discussed here.Note that this should not be a breaking change, because the CFE already reports this error.
The text was updated successfully, but these errors were encountered: