eclipse-archived/ceylon

Default type parameter from interface is not inferred in implementation

Opened this issue · 0 comments

Hi, this took me a while to pin down the issue as every try to extract the problem into some small test module from the project, was not invoking the issue. In Eclipse (Eclipse Java EE IDE for Web Developers. Version: Oxygen.1a Release (4.7.1a) Build id: 20171005-1200), the issue sometimes was visible in problems windows, on other times not. I was able to run unit tests, from separate module, so it had to build and import affected module and sometimes it was succesfull. This is strange and not appear on every occasion.

I have an interface which is defined as

shared interface Conversion<in Source=Nothing, out Result=Anything, in ResultType=Type<Result>> given ResultType satisfies Type<Result> {
    shared formal Result convert(Source source, ResultType type);
}

Interface defines API of generic conversion between types. As can be seen ResultType is defaulted to Type<Result>, so it should be inferred in implementations .

An example implementation (dummy)

shared class NullToStringConvertion() satisfies Conversion<Null,String>{
    shared actual String convert(Null source, Type<String> type) => "null";
}

When i put definition of interface and implementation in one file, module compiles fine, but when it is in separate files i get a compilation error

ceylon version 1.3.3 0d594b3 (Contents May Differ)

.../NullToStringConversion.ceylon:7: error: type of parameter 'type' of 'convert' declared by 'NullToStringConvestion' is different to type of corresponding parameter 'type' of refined member 'convert' of 'Conversion': type cannot be determined
    shared actual String convert(Null source, Type<String> type) => "null";
                                          	^
1 error

If dummy is implemented like

shared class NullToStringConvertion() satisfies Conversion<Null,String,Type<String>>{
    shared actual String convert(Null source, Type<String> type) => "null";
}

It compiles fine, should this be that way ?

I also saw something like this in one of compilation requests from terminal. I'm not sure if this is related but it is trying to compile KeyToValueMappingResolverTest.ceylon which is one of class from my test module.

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.RuntimeException: Error generating bytecode for .../KeyToValueMappingResolverTest.ceylon
	at com.redhat.ceylon.compiler.java.tools.LanguageCompiler.genCodeUnlessError(LanguageCompiler.java:839)
	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
Caused by: java.lang.AssertionError: typeSig ERROR
	at com.redhat.ceylon.langtools.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4852)
	at com.redhat.ceylon.langtools.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:299)
	at com.redhat.ceylon.langtools.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4814)
	at com.redhat.ceylon.langtools.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:299)
	at com.redhat.ceylon.langtools.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:342)
	at com.redhat.ceylon.langtools.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:1106)
	at com.redhat.ceylon.langtools.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1603)
	at com.redhat.ceylon.langtools.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1693)
	at com.redhat.ceylon.langtools.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1621)
	at com.redhat.ceylon.compiler.java.codegen.CeylonClassWriter.writeClass(CeylonClassWriter.java:62)
	at com.redhat.ceylon.compiler.java.tools.LanguageCompiler.genCodeUnlessError(LanguageCompiler.java:829)
	... 29 more