eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
395 stars 62 forks source link

switch case (is Integral<out Anything>) fails to match #7382

Closed kingjon3377 closed 6 years ago

kingjon3377 commented 6 years ago

I have a method like this one:

String truncateFloats(Number<out Anything> num) {
    switch (num)
    case (is Integral<out Anything>) {
        return num.string;
    }
    case (is Float) {
        return Float.format(num, 0, 2);
    }
    case (is Decimal) {
        return truncateFloats(num.float);
    }
    else {
        throw AssertionError("Unhandled Number type `` typeOf(num)``");
    }
}

If I pass it a Float or a Decimal, it works fine; if I pass in an Integer or a Whole, it reaches the "else" case and throws. This only happens on the Java backend; when I tried a simplified version (no Decimal case and without trying to test Whole) on try.ceylon-lang.org, it worked fine.

ceylon --version reports ceylon version 1.3.3 0d594b3 (Contents May Differ); if it matters, this is on Mac OS Sierra, and Ceylon was installed via Homebrew.

gavinking commented 6 years ago

This bug affects is tests with use-site variance annotations on self type arguments. Should be fixed.