eclipse-archived/ceylon

allow use-site variance in upper bound type constraints

Opened this issue · 2 comments

We've never supported wildcards in upper bound type constraints, mainly because we don't allow wildcards in supertypes of classes or interfaces, and because we didn't run into any strong need for them.

But Java allows them, and perhaps it would not cause much disruption to relax this restriction.

@RossTate do you see any problems with allowing stuff like given T satisfies MutableList<in String>?

Anyway, it's worth just trying it out to see if anything obviously breaks.

cc @jvasileff

Well, I made a totally trivial change to remove the limitation, and went looking for broken things. Surprisingly, everything I've tried seems to be working just fine!

I'm still looking for a way to break this.

Wildcards (without implicit constraints) don't cause any decidability issues (at least for common core features) if you've enforced material-shape separation and if you use mixed-site variance. (Mixed-site variance is simply the restriction saying that Foo<in ...> and Bar<out ...> are illegal types when Foo is declared to be covariant and Bar is declared to be contravariant.)