Skip to content

Unexpected overload selection involving covariant Array returned by java class #24074

@SrTobi

Description

@SrTobi

Compiler version

3.7.3

Minimized code

Java part:

public class JavaPart {
    public interface A { }
    public interface B extends A {
        int onlyInB();
    }

    public interface Lvl1 {
        A[] getData();
    }

    public interface Lvl2 extends Lvl1 {
        @Override
        B[] getData();
    }

    public interface Lvl3 extends Lvl2, Lvl1 { }
}

Scala part:

def test(lvl3: JavaPart.Lvl3): Unit =
  lvl3.getData.head.onlyInB()

Output

value onlyInB is not a member of JavaPart.A
    lvl3.getData.head.onlyInB()

Expectation

It should compile and lvl3.getData should resolve to Lvl2.getData.

The problem seems to be that Lvl1 is listed as last implemented interface in Lvl3 and thus the compiler selects Lvl1.getData.
If Lvl1 is moved before Lvl2 it works as expected. Also (lvl3: JavaPart.Lvl2).getData.head.onlyInB() makes it work as well.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions