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

[hl] conversion from Array<Null<T>> to Array<T> #6785

Open
Gama11 opened this Issue Dec 10, 2017 · 6 comments

Comments

Projects
None yet
4 participants
@Gama11
Copy link
Member

Gama11 commented Dec 10, 2017

The following works on all targets except HL:

class Main {
    static function main() {
       function foo(a:Array<Int>) trace(a);
       foo(([1, 2, 3] : Array<Null<Int>>));
    }
}
Uncaught exception: Can't cast #hl.types.ArrayObj to #hl.types.ArrayBytes_Int
Called from $Main.main(Main.hx:4)
Called from fun$337(?:1)
Error: Command failed with error 1

Haxe version: 37f6b2a
HashLink version: HaxeFoundation/hashlink@1b09bbb

@ncannasse

This comment has been minimized.

Copy link
Member

ncannasse commented Dec 10, 2017

I think that's to be expected, and Haxe 4 should prevent this at the typing level (no variance allowed between T and Null<T> if not is not nullable)

@ncannasse ncannasse added this to the 4.0 milestone Dec 10, 2017

@ncannasse ncannasse removed the platform-hl label Feb 25, 2018

@Simn Simn modified the milestones: Release 4.0, Design Apr 17, 2018

@ncannasse

This comment has been minimized.

Copy link
Member

ncannasse commented Nov 6, 2018

Any reason this is at Design phase and not Backlog ? Some potential issues to discuss ?

@Simn

This comment has been minimized.

Copy link
Member

Simn commented Nov 6, 2018

Well, we have to make up our minds about what kind of variance we want to allow with regards to Null<T>.

@ncannasse

This comment has been minimized.

Copy link
Member

ncannasse commented Nov 6, 2018

My suggestion would be to keep Null from T / to T, but Null should not unify with T when it comes to type parameters. So the above example would fail to compile with
Array<Null<Int>> should be Array<Int>

@Simn

This comment has been minimized.

Copy link
Member

Simn commented Nov 6, 2018

I mean, I certainly agree that this shouldn't unify. However, I'm not sure if type parameters should be a special case. There's also field- and function-argument-unification to consider for this. I closed #4342 because I figured we wouldn't make this change. If we want to go through with it after all we should do it properly...

@ncannasse

This comment has been minimized.

Copy link
Member

ncannasse commented Nov 7, 2018

I'm interested in experimenting with it and see how restricting Null / Int unification will affect the code base. Maybe we can try to have this on a branch first ? We can first go for almost zero unification and then see what kind of problems it causes for "valid and meaningful code".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment