Skip to content

Commit 2d23cba

Browse files
authored
Merge pull request #5454 from abeln/override-nullary
Fix #5453: method return type not checked when overriding nullary Java method
2 parents 9449ee4 + 193bac0 commit 2d23cba

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ object Types {
868868
matchLoosely && {
869869
val this1 = widenNullary(this)
870870
val that1 = widenNullary(that)
871-
((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(this1, matchLoosely = false)
871+
((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(that1, matchLoosely = false)
872872
}
873873
)
874874
}

tests/neg/i5453/J.java

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class J {
2+
String foo() { return "hello"; }
3+
}

tests/neg/i5453/S.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class S extends J {
2+
override def foo(): Int = 42 // error: incompatible return type
3+
}

0 commit comments

Comments
 (0)