eclipse-archived / ceylon

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

'name clash' error while overriding a Java method #6829

Open bjansen opened 7 years ago

bjansen commented 7 years ago

While trying to override this Java method in Ceylon, I get a name clash error whereas I think my signature is correct:

[ceylon-compile] /Users/bastien/Dev/ceylon/ceylon-ide-intellij/plugin-ceylon-code/source/org/intellij/plugins/ceylon/ide/ceylonCode/integrations/maven/CeylonMavenImporter.ceylon:65: error: Ceylon backend error: name clash: collectSourceRoots(MavenProject,PairConsumer<String,JpsModuleSourceRootType<? extends JpsElement>>) in CeylonMavenImporter and collectSourceRoots(MavenProject,PairConsumer<String,JpsModuleSourceRootType<?>>) in MavenImporter have the same erasure, yet neither overrides the other
[ceylon-compile]     shared actual void collectSourceRoots(MavenProject mavenProject,
[ceylon-compile]            ^
[ceylon-compile] /Users/bastien/Dev/ceylon/ceylon-ide-intellij/plugin-ceylon-code/source/org/intellij/plugins/ceylon/ide/ceylonCode/integrations/maven/CeylonMavenImporter.ceylon:49: error: Ceylon backend error: name clash: collectSourceRoots(MavenProject,PairConsumer<String,JpsModuleSourceRootType<? extends JpsElement>>) in CeylonMavenImporter and collectSourceRoots(MavenProject,PairConsumer<String,JpsModuleSourceRootType<?>>) in MavenImporter have the same erasure, yet neither overrides the other
[ceylon-compile] "Automatically configures Ceylon source roots from the POM."
[ceylon-compile] ^
[ceylon-compile] 2 errors

Java method:

public void collectSourceRoots(MavenProject mavenProject, 
        PairConsumer<String, JpsModuleSourceRootType<?>> result) {}

Ceylon override:

shared actual void collectSourceRoots(MavenProject mavenProject,
        PairConsumer<JString,JpsModuleSourceRootType<out Object>> result) {}

Replacing <out Object> with <out JpsElement> (as implied by the error message) does not fix the problem. I'm not sure how to reproduce it in a simple case though.

bjansen commented 7 years ago

Can reproduce with the following setup:

public class Parameterized { }

```java
import java.util.Map;

public abstract class Foo {
    public void bar(Map<String, Parameterized<?>> hello) {  
    }
}

Result:

source/foo/run.ceylon:10: error: type of parameter 'parameterized' of 'bar' declared by 'Ceylon' is different to type of corresponding parameter 'arg0' of refined member 'bar' of 'Foo': 'Map<String,Parameterized<out Object>>' is not exactly 'Parameterized<out Closeable>?'
    shared actual void bar(Map<String, Parameterized<out Object>> parameterized)
                           ^
source/foo/run.ceylon:11: error: argument must be assignable to parameter 'arg0' of 'bar' in 'Foo': 'Map<String,Parameterized<out Object>>' is not assignable to 'Parameterized<out Closeable>?'
            => super.bar(parameterized);
                         ^
2 errors

See attached sample project test.zip.