-
Notifications
You must be signed in to change notification settings - Fork 205
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
Implicit cast-and-construct from dynamic to extension type? #3369
Comments
Yes, I would expect I think it's fair to say that this treatment is covered by the existing specification of assignability, so there shouldn't be a need to put anything into the extension type specification about it. However, I would also hope that this initialization could be flagged by a lint saying that a cast to an extension type is a questionable action (cf. dart-lang/sdk#58838). |
Yes.
Yes. extension type E(int it) {}
void main() {
dynamic i = 7;
E j = i as E; // Implicit downcast from dynamic to context type.
} There is an implicit downcast from
No. It just gets cast. Casts are runtime operations. At runtime, extension types do not exist. They're completely gone, replaced by their representation type. The code that actually runs will be: void main() {
dynamic /*aka Object?*/ i = 7;
int j = i as int;
}
I think it is. It might be implicit, because it is a consequence of the interaction of how extension types work at compile-time and at runtime, and completely standard behavior.
|
Thanks! Filed dart-lang/sdk#59310 |
The (only?) implicit cast we have left (I think I'm not including coersions...) is "from dynamic to anything". So in this code:
Is this legal? Does
i
get implicitly cast toE
which invokesE
's primary constructor? I think this is all expected and fine, but it's not really spelled out in the spec, I think.CC @eernstg
The text was updated successfully, but these errors were encountered: