Skip to content
Browse files

fix type checking of argument to self types in satisfies

  • Loading branch information...
1 parent 3103b48 commit 6e1bb8af3f7307a4408a98898fd982752f2adaff @gavinking gavinking committed
View
13 src/com/redhat/ceylon/compiler/typechecker/analyzer/ExpressionVisitor.java
@@ -3859,7 +3859,7 @@ private void checkExtensionOfMemberType(Node that, TypeDeclaration td,
}
}
- private void checkSelfTypes(Node that, TypeDeclaration td, ProducedType type) {
+ private void checkSelfTypes(Tree.StaticType that, TypeDeclaration td, ProducedType type) {
if (!(td instanceof TypeParameter)) { //TODO: is this really ok?!
List<TypeParameter> params = type.getDeclaration().getTypeParameters();
List<ProducedType> args = type.getTypeArgumentList();
@@ -3877,10 +3877,13 @@ private void checkSelfTypes(Node that, TypeDeclaration td, ProducedType type) {
TypeDeclaration mtd = (TypeDeclaration) td.getMember(std.getName(), null, false);
at = mtd==null ? null : mtd.getType();
}
- if (at!=null) {
- checkAssignable(at, arg, std, that,
- "type argument does not satisfy self type constraint on type parameter " +
- param.getName() + " of " + type.getDeclaration().getName());
+ if (at!=null && !at.isSubtypeOf(arg) &&
+ !(td.getSelfType()!=null &&
+ td.getSelfType().isExactly(arg))) {
+ that.addError("type argument does not satisfy self type constraint on type parameter " +
+ param.getName() + " of " + type.getDeclaration().getName() + ": " +
+ arg.getProducedTypeName() + " is not a supertype or self type of " +
+ td.getName());
}
}
}
View
24 test/main/typing/SelfType.ceylon
@@ -77,3 +77,27 @@ interface Aa {}
@error interface Bb satisfies Comparable<Bb&Aa> {}
@error interface Cc satisfies Comparable<Cc|Aa> {}
@error interface Zz satisfies Comparable<Bb|Cc|Aa> {}
+
+interface A satisfies Comparable<C|A> {}
+interface C satisfies Comparable<C|A> {}
+
+interface Comp<in T> of T
+ given T satisfies Comp<T> {
+ shared formal Comparison compare(T other);
+}
+
+interface Scal<in T> of T
+ satisfies Comp<T>
+ given T satisfies Scal<T> {}
+
+class CompBar() satisfies Comp<CompBar> {
+ shared actual Comparison compare(CompBar other) {
+ return bottom;
+ }
+}
+
+@error class CompFoo() satisfies Comp<CompBar> {
+ shared actual Comparison compare(CompBar other) {
+ return bottom;
+ }
+}

0 comments on commit 6e1bb8a

Please sign in to comment.
Something went wrong with that request. Please try again.