ceylon/ceylon-spec — Issue #153: Variance issue with attributes
Author: FroMage
Created: 2012-01-31 16:39:56+00:00
State: open
Labels: bug

I've noticed another issue related to contravariance. In Ceylon it's legal to refine an attribute with a "finer" type, because it is covariant. But variable attributes too, even though this makes the attribute sort-of contravariant.

For ex:

```java
interface VarianceTop {}
interface VarianceMiddle satisfies VarianceTop {}
interface VarianceBottom satisfies VarianceMiddle {}

class VarianceClass(VarianceMiddle classParam){
shared variable default VarianceMiddle classAttr := classParam;
}
class VarianceSubClass(VarianceBottom classParam) extends VarianceClass(classParam){
shared variable actual VarianceBottom classAttr := classParam;
}
```

So here we have an issue because we can assign to `VarianceClass.classParam` objects of type `VarianceMiddle` but if we try this on an instance of `VarianceSubClass` it will break because that type is too "wide".

There's something wrong with covariance on variable attributes, no?