ceylon / ceylon-spec

DEPRECATED
Apache License 2.0
108 stars 34 forks source link

type parameters on the LHS of = #1329

Open gavinking opened 9 years ago

gavinking commented 9 years ago

Currently we don't let you write:

T fun<T>(T x);
fun<T>(T x) => x;

Nor do we let you use the shortcut refinement syntax for generic methods.

I think this is a limitation that should be removed, assuming it's not impossible to parse.

gavinking commented 9 years ago

Actually there's a bug here that I didn't know about: in fun<T>(T x) the <T> gets treated as a type argument list. Which results in the typechecker actually accepting this code:

    T fun<T>(T x);
    fun<String>(String x) => x;

Oops!

gavinking commented 9 years ago

OK, so this one, it turns out is really tricky, due to something rubbish in the model that is probably the source of other bugs that I'm surprised we have not run into yet.

Basically, in DeclarationVisitor, the Parameters and TypeParameters belonging to a specification statement wind up getting their parent declaration set to point to the innermost containing declaration, since the Specification itself doesn't count as a Declaration.

This means that we can wind up with a bunch of models with the same names and parents which really screws up the equals() and hashCode() of at least TypeParameter.

Something needs to be done to fix this, since it's really super-fragile right now.