Skip to content

Could not recognize 'BoxedUnit' in Java as 'Unit'  #22312

Open
@XYZboom

Description

@XYZboom

Compiler version

3.6.3-RC2, 3.6.4-RC1-bin-20241231-1f0c576-NIGHTLY
(Tried in 2.13.15 too, but I don't know if it's necessary to report it to Scala 2 at the same time)

Minimized code

trait I0[T] {
  def func(): T
}
trait I1 extends I0[Unit] {
}
class A1 extends A0 {
  override def func(): Unit = ???
}
// Java File
// FILE: A0.java
import scala.runtime.BoxedUnit;

public class A0 implements I1 {
    @Override
    public BoxedUnit func() {
        return BoxedUnit.UNIT;
    }
}

Output

A0.scala:7:16
error overriding method func in class A0 of type (): scala.runtime.BoxedUnit;
  method func of type (): Unit has incompatible type
  override def func(): Unit = ???

If change Unit into BoxedUnit, like this:

class A1 extends A0 {
  override def func(): BoxedUnit= ???
}

another error occurs:

A0.scala:9:16
error overriding method func in trait I0 of type (): Unit;
  method func of type (): scala.runtime.BoxedUnit has incompatible type
  override def func(): BoxedUnit = ???

Expectation

The above code should compile successfully.

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