Skip to content

Commit a03dee7

Browse files
committed
Fix scala#9392: Allow override no-params java-defined methods which have a field with same name
1 parent 7427fb8 commit a03dee7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,22 @@ object OverridingPairs {
4040
* relative to <base>.this do
4141
*/
4242
protected def matches(sym1: Symbol, sym2: Symbol): Boolean =
43-
sym1.isType || sym1.asSeenFrom(self).matches(sym2.asSeenFrom(self))
43+
// Similar to dotty.tools.dotc.core.Denotations.SingleDenotation.matches
44+
// But in case MethodNotAMethodMatch, sym2 must not be a JavaDefined field
45+
def symMatches =
46+
val d1 = sym1.asSeenFrom(self)
47+
val d2 = sym2.asSeenFrom(self)
48+
import Signature.MatchDegree._
49+
d1.signature.matchDegree(d2.signature) match
50+
case FullMatch => true
51+
case NoMatch => false
52+
case MethodNotAMethodMatch =>
53+
!ctx.erasedTypes && !d2.symbol.is(JavaDefinedVal, butNot = Method)
54+
case ParamMatch =>
55+
!ctx.erasedTypes && d1.info.matches(d2.info)
56+
57+
sym1.isType || symMatches
58+
end matches
4459

4560
/** The symbols that can take part in an overriding pair */
4661
private val decls = {

0 commit comments

Comments
 (0)