-
Notifications
You must be signed in to change notification settings - Fork 2
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
Null<T> #3
Comments
Ahh, true! I can see how this would become a headache 🤔
Reference types can already be assigned But it would probably suck to just wrap all the custom value types in a reference type, removes the whole point of their optimization. Hmmmm... guess @:struct types can just throw an error if found being assigned a @Simn Sorry if this has been asked before, but I've been meaning to inquire: is having null-safety always "on" on the table for Haxe 5? Outside of the safety stuff, feels like it would help with optimizing generation for static targets for situations like this. But would probably break everything... so idkkk... |
As far as I can tell, I would see the generated code like this:
But yes, that won't solve all cases, like if in the original Haxe code there is some generic class or function literally taking If there is no going away from this, I guess we should try our best to use a custom Nullable type only in places where we can't do otherwise (like haxe generic |
Regarding default null-safety, I don't know yet. It might become a thing like DCE that is enabled by default for user-code. But at the end of the day, the problem here isn't going to go away. |
@Simn Do you have more details about the problems/friction you had when using that custom |
I never used it much, but from my understanding it makes native interop a mess. Maybe @kLabz has some insight, he's the expert on Haxe/C# annoyances. |
One of the biggest challenges when it comes to Haxe code generation is the handling of
Null<T>
. My experience is that it's good to get this out of the way early because otherwise it's going to come back with a vengeance.The problem with C# Nullable is that it is constrained to
struct
. This means that it cannot be used with reference types, which in turn means that it cannot be "blindly" used in place of Haxe'sNull<T>
. Unfortunately, I don't remember what exactly the problem was with an approach that would emitNullable
only if the parameter is not a reference type.The C# target has its own Null implementation that doesn't have the struct restriction. However, this has always caused some friction and doesn't seem ideal either.
I'm interested in knowing what the best approach is in the C# world!
The text was updated successfully, but these errors were encountered: