-
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
"RuntimeError: illegal cast" when casting value to a type parameter whose bound is a nullable extension type #53968
Comments
Hi, just to make sure you aren't working on the semantics of extension types based on a rule which is being updated, I'd like to mention a thing: In dart-lang/language#3434, the definition of 'being nullable' for extension types is changed: It used to be based on the nullability of the representation type. With the change proposed in that PR, it is based on explicit superinterface declarations ( So an extension type The change has been accepted by the language team, so the essence of it is in place today. So dart-lang/language#3434 hasn't landed yet, but we are just debating the choice of words, not the meaning. I'm sorry about introducing changes that might be substantial at this time, but I think we will be happy about the new rule because it's considerably simpler (and more in line with the rest of the language). [Edit: Corrected 'nullable' to 'non-nullable' in paragraph 3.] |
@eernstg Just so I'm understanding this clearly:
I'm guessing this is supposed to be "non-nullable"? In which case cc @johnniwinther because this affects the type erasure algorithm in the AST |
The extension type rules should have no (direct) effect on the runtime behavior, since extension types should have been effectively erased at runtime. Whether the extension type is itself nullable or not shouldn't change what, effectively, |
Right, thanks! I corrected this in my comment above.
We have no rules that makes So I think it all makes sense, and I'd say that the example in the original post should be accepted at compile time, and it should succeed at run time. The actual type argument passed to the invocation of |
Extension types use precisely the same rules for being nullable or being non-nullerne as every other type: |
Thank you both for the comments! Maybe this comment is better suited in the proposal thread (and we can certainly move the discussion there if desired), but if we had a function void f<X extends Object>() {}
If I understand correctly, if I want to get non-nullable semantics, I should have an |
You can't "implement That hasn't changed, the only thing that was changed was whether some extension types implements |
At least the ones that don't have a path to |
The CFE change to require |
The CL tying extension type non-nullability to implementing |
It seems like the fix in #53968 (comment) is irrelevant, so this needs a separate fix. @ the dart2wasm folks, is there anything I can help with to fix this? I think this is going to generally block us from moving to extension types. |
Tentative fix: https://dart-review.googlesource.com/c/sdk/+/339400 |
Dart SDK version:
3.3.0-edge.8f23c4a91687f3eb59746f00fe75ca5f162bd0d3 (be) (Thu Nov 2 16:28:57 2023 -0700) on "macos_x64"
Browser: Both d8 and Chrome
results in:
This seems to result specifically from a combination of the nullable extension type type parameter bound and a value of null. Doing any of the following does not reproduce this:
0 as T
instead ofnull
A
nullablenull as A
instead ofT
My best guess is that we're losing the nullability of the extension type somewhere.
This popped up when I was migrating JS types to extension types, specifically here (when the property get result is
null
):sdk/sdk/lib/_internal/wasm/lib/js_interop_unsafe_patch.dart
Line 22 in 18c8a50
Neither DDC or dart2js reproduce this issue.
The text was updated successfully, but these errors were encountered: