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 argument is not checked #961

Closed
simonthum opened this issue May 3, 2014 · 7 comments
Closed

Default type argument is not checked #961

simonthum opened this issue May 3, 2014 · 7 comments
Assignees
Milestone

Comments

@simonthum
Copy link
Contributor

This passes the type checker:

shared interface TraitB<Representation  = Integer> given Representation satisfies TraitB<Representation> {
    shared formal Representation modfiyB();
}

But you cannot do much without assigning some legal type to Representation.

@lucaswerkmeister
Copy link
Member

Note that this is a typechecker bug, not a spec oversight: The spec clearly states that

The default type argument must satisfy the constraints on the type parameter.

@simonthum
Copy link
Contributor Author

@lucaswerkmeister I am unsure if I understand you correctly.

My assumption is that it is not currently checked, because it passes. It plainly does not make nay sense not to check it. So it would be an oversight or a bug - I just assumed the spec contains this simple corollary.

Then, as far as I know, this repo contains the typechecker, so this seems the right place. Anything wrong?

@lucaswerkmeister
Copy link
Member

No, everything is correct. I just wanted to clarify that is a pure bug, and not something that was forgotten in the textual specification.

@simonthum
Copy link
Contributor Author

Sure, thanks for making up for my brevity!

@FroMage FroMage added the bug label May 5, 2014
@FroMage FroMage added this to the 1.1 milestone May 5, 2014
@FroMage
Copy link
Member

FroMage commented May 5, 2014

Looks like a bug, thanks!

@lucaswerkmeister
Copy link
Member

Some more info:

class K<T=Integer>()
        given T satisfies String {
}

void run() {
    K k1 = nothing; // well-typed, and the IDE says it is indeed a K<Integer>
    K<Integer> k2 = nothing; // error: Integer not assignable to upper bound String
    K k3 = K(); // error: K<Nothing> not assignable to K<Integer> – this error vanishes if you declare T as out
}

Note especially k3 – it seems the typechecker is constructing the intersection of the default type argument and the type parameter’s constraint when instantiating the class.

@gavinking
Copy link
Member

Fixed by @928061f.

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

No branches or pull requests

4 participants