From 32a10d50b27e2a9ca6437425eebd4a29bef756fc Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 30 Jul 2020 16:37:43 +0200 Subject: [PATCH] Consistent override checking In 7964d17506a152a38c5b482475a51947b251ca78, `OverridingPairs.Cursor#matches` was changed to use Denotations#matches instead of Types#matches to make the override check more precise, but the same was not done in `RefChecks#checkAllOverrides#hasMatchingSym#isSignatureMatch`, which lead to inconsistencies: in the added testcase, the definition of `foo` in `B` doesn't override anything, but because OverridingPairs and RefChecks disagreed on what an override was, that did not produce any error. --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 6 ++++-- tests/neg/i9109.scala | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i9109.scala diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index afb5e1a03b41..ba6302f335de 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -762,8 +762,10 @@ object RefChecks { */ def hasMatchingSym(inclazz: Symbol, member: Symbol): Boolean = { - def isSignatureMatch(sym: Symbol) = !sym.isTerm || - clazz.thisType.memberInfo(sym).matchesLoosely(member.info) + def isSignatureMatch(sym: Symbol) = sym.isType || { + val self = clazz.thisType + sym.asSeenFrom(self).matches(member.asSeenFrom(self)) + } /* The rules for accessing members which have an access boundary are more * restrictive in java than scala. Since java has no concept of package nesting, diff --git a/tests/neg/i9109.scala b/tests/neg/i9109.scala new file mode 100644 index 000000000000..7f17a24ffd54 --- /dev/null +++ b/tests/neg/i9109.scala @@ -0,0 +1,6 @@ +class A { + def foo[T <: Cloneable](x: T): Unit = {} +} +class B extends A { + override def foo[T <: Serializable](x: T): Unit = {} // error: method foo has a different signature than the overridden declaration +}