Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JVM backend error on nested generic ADT #2413

Open
pthariensflame opened this issue Nov 2, 2015 · 1 comment
Open

JVM backend error on nested generic ADT #2413

pthariensflame opened this issue Nov 2, 2015 · 1 comment
Labels
Milestone

Comments

@pthariensflame
Copy link

The following code causes backend errors on the marked lines:

shared class Measured<Type, out Measure>() {}

shared final class FingerTree<out Measure, Element> {
    class Node<out Elem>(shared Measure val, shared Elem[2]|Elem[3] elems)
            given Elem satisfies Object {}

    class Digit<out Elem>(shared Elem[1]|Elem[2]|Elem[3]|Elem[4] elems)
            given Elem satisfies Object {}

    abstract class Tree<out Elem>() of Empty | Single<Elem> | Deep<Elem>
            given Elem satisfies Object {}
    final class Empty() extends Tree<Nothing>() {} // error
    final class Single<out Elem>(shared Elem elem) extends Tree<Elem>() // error
            given Elem satisfies Object {}
    final class Deep<out Elem>( // error
        shared Measure val,
        shared Digit<Elem> left,
        shared Tree<Node<Elem>> middle,
        shared Digit<Elem> right
    ) extends Tree<Elem>()
            given Elem satisfies Object {}

    shared Measured<Element,Measure> localMeasured;
    Tree<Element> tree;

    shared new empty(Measured<Element,Measure> measured) {
        localMeasured = measured;
        tree = Empty();
    }
}

The error in question is identical on all three lines, and it is:

Unexpected type
 required: class or interface without bounds
 found:    ? extends Elem

@gavinking said on https://gitter.im/ceylon/user that this was a compiler bug, and asked me to report it here.

@pthariensflame
Copy link
Author

Here is a minimal example of the bug:

class A() {
    abstract class B<out X>() of C<X> {}
    class C<out X>() extends B<X>() {} // error
}

Changing out to in in both places produces a similar-looking backend error, with ? extends X swapped for ? super X. Oddly enough, removing the variance annotation entirely also eliminates the backend error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants