eclipse-archived/ceylon

Backend errors when union type given to type parameter

Opened this issue · 1 comments

The following code fails to compile with two backend errors on the same line:

interface Interface<Type> given Type satisfies SuperInterface {
    shared formal void process(Map<Integer, [String, SuperInterface]> map, Type item, String final);
    shared formal void processMany(Map<Integer, [String, SuperInterface]> map);
}
interface SuperInterface {}
interface SecondInterface satisfies SuperInterface {}
class SimpleClass() satisfies SuperInterface {}
class Implementation() satisfies Interface<SecondInterface|SimpleClass> {
    shared actual void process(Map<Integer, [String, SuperInterface]> map,
        SecondInterface|SimpleClass item, String final) {}
    shared actual void processMany(Map<Integer, [String, SuperInterface]> map) {
        for ([first, second] in map.
                narrow<Integer->[String, SecondInterface|SimpleClass]>().map(Entry.item)) {
             // On the open parenthesis below: error: Ceylon backend error: method invoked with incorrect number of arguments; expected 3, found 0
             // On 'second' below: error: Ceylon backend error: incompatible types: Object cannot be converted to SuperInterface
            process(map, second, first);
        }
    }
}

ceylon --version reports ceylon version 1.3.3 0d594b3 (Contents May Differ); if it's relevant, this is on Mac OS X Sierra. I see the same thing on the command line (installed via Homebrew) and in Eclipse.

I've just distilled another case that looks like this same bug, and in addition to the "Ceylon backend error"s, it spews a CompilerBugException stack trace.

The code:

shared interface DataInterface {}
shared class A() satisfies DataInterface {}
shared class B() satisfies DataInterface {}
shared class C() satisfies DataInterface {}

shared interface ErrorInterface<T> given T satisfies DataInterface {
    shared formal {{String+}*} produce(T item, Integer key);
}

shared class ErrorClass()
        satisfies ErrorInterface<A|B|C> {
    shared actual [{String+}+] produce(A|B|C item, Integer key) => [["", "", ""]];
    shared void produceTable() {
        {[Integer, [A|B|C]]*} values = [];
        for ([key, [item]] in values) {
            switch (item)
            case (is A) {}
            case (is B|C) {
                value [row, *_] = produce(item, key);
            }
        }
    }
}

The compiler output:

source/mwe/mwe.ceylon:19: error: Ceylon backend error: incompatible types: Object cannot be converted to DataInterface
                value [row, *_] = produce(item, key);
                                          ^
source/mwe/mwe.ceylon:19: error: Ceylon backend error: method invoked with incorrect number of arguments; expected 2, found 0
                value [row, *_] = produce(item, key);
                                         ^
Note: Created module mwe/0.0.1
ceylon compile: Fatal error: The compiler exited abnormally (4) due to a bug in the compiler.
Please report it:
 https://github.com/ceylon/ceylon/issues/new
Please include:

* the stacktrace printed below
* a description of what you were trying to compile.

Thank you!
com.redhat.ceylon.compiler.CompilerBugException: Bug
	at com.redhat.ceylon.compiler.CeylonCompileTool.handleExitCode(CeylonCompileTool.java:933)
	at com.redhat.ceylon.compiler.CeylonCompileTool.run(CeylonCompileTool.java:915)
	at com.redhat.ceylon.common.tools.CeylonTool.run(CeylonTool.java:547)
	at com.redhat.ceylon.common.tools.CeylonTool.execute(CeylonTool.java:423)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.redhat.ceylon.launcher.Launcher.runInJava7Checked(Launcher.java:108)
	at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:38)
	at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.redhat.ceylon.launcher.Bootstrap.runVersion(Bootstrap.java:162)
	at com.redhat.ceylon.launcher.Bootstrap.runInternal(Bootstrap.java:117)
	at com.redhat.ceylon.launcher.Bootstrap.run(Bootstrap.java:93)
	at com.redhat.ceylon.launcher.Bootstrap.main(Bootstrap.java:85)
Caused by: java.lang.ClassCastException: com.redhat.ceylon.langtools.tools.javac.code.Symbol$ClassSymbol cannot be cast to com.redhat.ceylon.langtools.tools.javac.code.Symbol$MethodSymbol
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitApply(Gen.java:1847)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1464)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genExpr(Gen.java:949)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitVarDef(Gen.java:1146)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:851)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStats(Gen.java:811)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitBlock(Gen.java:1159)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:908)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitIf(Gen.java:1755)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1268)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitIf(Gen.java:1761)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1268)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStats(Gen.java:811)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitBlock(Gen.java:1159)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:908)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStats(Gen.java:811)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitBlock(Gen.java:1159)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:908)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genLoop(Gen.java:1208)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitWhileLoop(Gen.java:1173)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCWhileLoop.accept(JCTree.java:964)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitLabelled(Gen.java:1239)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCLabeledStatement.accept(JCTree.java:1061)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:760)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStats(Gen.java:811)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitBlock(Gen.java:1159)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:908)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genStat(Gen.java:774)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genMethod(Gen.java:1033)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.visitMethodDef(Gen.java:996)
	at com.redhat.ceylon.langtools.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:777)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genDef(Gen.java:739)
	at com.redhat.ceylon.langtools.tools.javac.jvm.Gen.genClass(Gen.java:2461)
	at com.redhat.ceylon.compiler.java.tools.LanguageCompiler.genCodeUnlessError(LanguageCompiler.java:810)
	at com.redhat.ceylon.compiler.java.tools.LanguageCompiler.genCode(LanguageCompiler.java:776)
	at com.redhat.ceylon.langtools.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1575)
	at com.redhat.ceylon.compiler.java.tools.LanguageCompiler.generate(LanguageCompiler.java:953)
	at com.redhat.ceylon.langtools.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1539)
	at com.redhat.ceylon.langtools.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:904)
	at com.redhat.ceylon.langtools.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:862)
	at com.redhat.ceylon.compiler.java.tools.LanguageCompiler.compile(LanguageCompiler.java:270)
	at com.redhat.ceylon.compiler.java.launcher.Main.compile(Main.java:660)
	at com.redhat.ceylon.compiler.java.launcher.Main.compile(Main.java:563)
	at com.redhat.ceylon.compiler.java.launcher.Main.compile(Main.java:555)
	at com.redhat.ceylon.compiler.java.launcher.Main.compile(Main.java:544)
	at com.redhat.ceylon.compiler.CeylonCompileTool.run(CeylonCompileTool.java:914)
	... 17 more

ceylon --version is the same as above.