-
-
Notifications
You must be signed in to change notification settings - Fork 658
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> inference #7736
Comments
@ncannasse: How do you feel about this? It seems correct to me to infer class Main {
static public function main() {
var a = null;
a = "foo";
$type(a); // Null<String>
var b = "foo";
b = null;
$type(b); // String
}
} I suppose this is consistent with our general unification behavior though. |
@Simn atm not auto-typing things as |
Type inference is always affected by order though? For instance this doesn't seem much different to me: class Main {
static function main() {
var a = [];
a.push(new Parent());
$type(a); // Array<Parent>
a.push(new Child()); // works
var a = [];
a.push(new Child());
$type(a); // Array<Child>
a.push(new Parent()); // fails
}
}
class Parent { public function new() {} }
class Child extends Parent { public function new() { super(); } } |
That's the conclusion I arrived at too. It's not really different from assigning Int and Float values where the order matters as well. I think we should infer |
I have looked into this today and I believe we should infer
I think that the only thing it can possibly break is the
I would personally just remove the check altogether because I don't see its benefits: nowadays we have |
Funny to see same And some ideas about workarounds would be nice. Migration to null safety can be complicated with such holes, so maybe something like |
There's some inference problem in the neko standard library of all places. I'm dodging this for now, but will have to check what's going on there and if it happens in "real" code too. |
I just saw that haxelib didn't compile with the previous commit. There were some errors about "recursive types". |
Yes that was the problem I'm dodging now. Although now there's some new problem... |
Would be nice if
Null<T>
was inferred here, so it compiles with null safety enabled:In that case it would be
Null<Unknown<0>>
in the first$type
andNull<String>
for the second.The text was updated successfully, but these errors were encountered: