Skip to content

Type mismatch calling interface with method override #12892

Open
@tpetillot

Description

@tpetillot

Reproduction steps

Scala version: 2.13.12

Java interfaces:

interface Parent {
  default Object bug() {
    return "Hello world";
  }
}

interface Child extends Parent {
  @Override
  String bug();
}

Problem

Do compile in Java:

public class MainJava {
  public static void main(String[] args) {
      Child child = null;
      String value = child.bug();
  }
}

Do not compile in Scala:

object MainScala {
  def main(args: Array[String]): Unit = {
    val child: Child = null
    val value: String = child.bug()
  }
}

Result:

[error] type mismatch;
[error] found   : Object
[error] required: String
[error]     val value: String = child.bug()

Java and Scala implementation should have the same behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)java interop

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions