From 193bac080c91ecc3840de4926ebbdf60845033b7 Mon Sep 17 00:00:00 2001 From: Abel Nieto Date: Fri, 16 Nov 2018 11:14:21 -0500 Subject: [PATCH] Fix #5453: method return type not checked when overriding nullary Java method --- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- tests/neg/i5453/J.java | 3 +++ tests/neg/i5453/S.scala | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i5453/J.java create mode 100644 tests/neg/i5453/S.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 3122e5f90217..b101ada545cb 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -868,7 +868,7 @@ object Types { matchLoosely && { val this1 = widenNullary(this) val that1 = widenNullary(that) - ((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(this1, matchLoosely = false) + ((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(that1, matchLoosely = false) } ) } diff --git a/tests/neg/i5453/J.java b/tests/neg/i5453/J.java new file mode 100644 index 000000000000..c957a1f307b6 --- /dev/null +++ b/tests/neg/i5453/J.java @@ -0,0 +1,3 @@ +class J { + String foo() { return "hello"; } +} diff --git a/tests/neg/i5453/S.scala b/tests/neg/i5453/S.scala new file mode 100644 index 000000000000..90776871187b --- /dev/null +++ b/tests/neg/i5453/S.scala @@ -0,0 +1,3 @@ +class S extends J { + override def foo(): Int = 42 // error: incompatible return type +}