Permalink
Browse files

fix #342

  • Loading branch information...
1 parent c281736 commit 5f7cdcec66ad7d6c4b83b39a710f275438e0727c @gavinking gavinking committed Jun 21, 2012
View
17 src/com/redhat/ceylon/compiler/typechecker/analyzer/RefinementVisitor.java
@@ -122,7 +122,24 @@ private boolean isVisible(Declaration member, TypeDeclaration type) {
for (int j=i+1; j<supertypes.size(); j++) {
ProducedType st2 = supertypes.get(j);
if (st1.getDeclaration().equals(st2.getDeclaration()) /*&& !st1.isExactly(st2)*/) {
+ boolean ok = true;
if (!st1.isSubtypeOf(st2) && !st2.isSubtypeOf(st1)) {
+ ok = false;
+ }
+ else {
+ //TODO: type arguments of the qualifying type?
+ //can't inherit two instantiations of a contravariant type, since
+ //we don't support contravariant refinement of parameter types
+ for (TypeParameter tp: st1.getDeclaration().getTypeParameters()) {
+ ProducedType ta1 = st1.getTypeArguments().get(tp);
+ ProducedType ta2 = st2.getTypeArguments().get(tp);
+ if (!tp.isCovariant() && !ta1.isExactly(ta2)) {
+ ok = false;
+ break;
+ }
+ }
+ }
+ if (!ok) {
that.addError("type " + td.getName() +
" has the same supertype twice with incompatible type arguments: " +
st1.getProducedTypeName() + " and " + st2.getProducedTypeName());
View
4 test/main/typing/Generics.ceylon
@@ -414,7 +414,7 @@ class Generics() {
interface Super1 satisfies Inter1<Bottom> & Inter2<String> {}
interface Super2 satisfies Inter1<Integer> & Inter2<Object> {}
- class Impl() satisfies Super1 & Super2 {}
+ @error class Impl() satisfies Super1 & Super2 {}
value impl = Impl();
String implget1 = impl.get();
@error Integer implget2 = impl.get();
@@ -427,7 +427,7 @@ class Generics() {
interface Super3 satisfies Inter1<Object> & Inter2<String> {}
interface Super4 satisfies Inter1<Integer> & Inter2<Bottom> {}
- class Conc() satisfies Super3 & Super4 {}
+ @error class Conc() satisfies Super3 & Super4 {}
value conc = Conc();
String concget1 = conc.get();
Integer concget2 = conc.get();

0 comments on commit 5f7cdce

Please sign in to comment.