Skip to content
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

Default type parameters vs constraints #11556

Closed
kLabz opened this issue Feb 7, 2024 · 2 comments
Closed

Default type parameters vs constraints #11556

kLabz opened this issue Feb 7, 2024 · 2 comments

Comments

@kLabz
Copy link
Contributor

kLabz commented Feb 7, 2024

We can currently define default type parameters that are not compatible with their constraints:

class Foo<T:EnumValue = Void> {
    public var data:T;
    public final function new() {}
}

https://try.haxe.org/#8B325355

When used, type inference will use a monomorph there:

    // This is fine
    var e = new Foo();
    $type(e.data); // Unknown<0> : EnumValue

But when explicitly using the default type parameter, it'll fail as expected:

    // This is not fine
    var e:Foo = new Foo();
    $type(e.data); // Void
[ERROR] Test.hx:7: characters 5-27

 7 |     var e:Foo = new Foo();
   |     ^^^^^^^^^^^^^^^^^^^^^^
   | error: Void should be EnumValue
   | have: Foo<Void>
   | want: Foo<EnumValue>

We should probably catch that early, directly in class Foo<T:EnumValue = Void> declaration

@Simn
Copy link
Member

Simn commented Feb 7, 2024

I vaguely remember us saying "this is fine", but looking at it I'd also expect this to fail.

@Simn
Copy link
Member

Simn commented Feb 7, 2024

Closed by 060ff56

@Simn Simn closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants