Skip to content

Cannot extend some Scala abstract classes from Java #23961

@hamzaremmal

Description

@hamzaremmal

Compiler version

dfacd3f

Minimized code

Scala File:

class Box[T]

trait Foo:
    def foo: Box[this.type] = ???

abstract class Bar extends Foo:
    override def foo: Box[this.type] = ???

Java file:

class JBar extends Bar { }

Output

Javac will complain.

test.java:1: error: foo() in Bar cannot implement foo() in Foo
class JBar extends Bar { }
^
  return type Box<Bar> is not compatible with Box<Foo>
1 error

Expectation

To work. Although, this is up to debate.

Note

Changing the trait to an abstract class works. I believe this is actually a bug in the JVM given that this is against the specification.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions