-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
[typer] Monomorph vs Null<T> inference #11753
base: development
Are you sure you want to change the base?
Conversation
42c2aad
to
2c3c380
Compare
This is still wrong.. monomorph is closed, which breaks the following: static function doThingsImpl(foo) {
$type(foo); // Unknown<0>
foo.doWithBar();
$type(foo); // Unknown<0> : { doWithBar : () -> Unknown<1> }
$type(foo.doWithBar); () -> Unknown<0>
if (foo != null) trace(foo);
$type(foo); // Null<{ doWithBar : () -> Unknown<0> }>
$type(foo.doWithBar); // () -> Unknown<0>
foo.test(); // Null<{ doWithBar : () -> Unknown<0> }> has no field test
} With class Foo {
public function new() {}
public function test() {}
public function doWithBar(?bar:Bar) {
trace(bar);
}
} |
My intuition here would be to only do this |
Sounds like it would only cover a few use cases (but at least it wouldn't be broken). |
I agree, ideally the nullability of a monomorph would be a property of the monomorph itself, not some wrapper type which easily gets lost. I'm not sure how complicated such a change would be, but in theory we can decorate monomorphs with any number of flags. I vaguely recall wanting to have some sort of "allows array access" flag on them too which would work in a similar fashion. |
Yeah, that sounds like a necessary rabbit hole (but I guess other constraints could be added later if needed rather than all at once). I started a POC adding that nullability flag; things were not quite working but I could revive that and look into it a bit more since we seem to agree on the theory there |
This is a regression introduced in 4.3.0 with 02a7f98
This can also lead to
Fatal error: exception Invalid_argument("List.map2")
in genhl with a slightly different example.Also allows this kind of things https://try.haxe.org/#05A1D90d
4.2.5
Since 4.3.0
Notice how we lose the
doWithBar
typing:With this PR