Skip to content

Method return type not checked when overriding nullary Java method #5453

Closed
@abeln

Description

@abeln

In Java,

class J {
  String foo() { return "foo"; }
}

In Scala,

class S extends J {
  override def foo(): Int = 42
}

Expected (scalac):

S.scala:6: error: overriding method foo in class J of type ()String;
 method foo has incompatible type
  override def foo(): Int = ???
               ^

Actual (dotc):
Compilation succeeds

The problem is in https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/core/Types.scala#L871

Specifically, this1.overrides(this1, matchLoosely = false) should be this1.overrides(that1, matchLoosely = false).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions