Skip to content

Fix #9392. Allow override java defined methods which have a field with same name #9395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ object Denotations {
relaxed && !symbol.is(JavaDefined)
case ParamMatch =>
relaxed
case noMatch =>
case NoMatch =>
false
if matches then this else NoDenotation

Expand Down Expand Up @@ -981,7 +981,7 @@ object Denotations {
case ParamMatch =>
// The signatures do not tell us enough to be sure about matching
!ctx.erasedTypes && info.matches(other.info)
case noMatch =>
case NoMatch =>
false
end matches

Expand Down
17 changes: 16 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,22 @@ object OverridingPairs {
* relative to <base>.this do
*/
protected def matches(sym1: Symbol, sym2: Symbol): Boolean =
sym1.isType || sym1.asSeenFrom(self).matches(sym2.asSeenFrom(self))
// Similar to dotty.tools.dotc.core.Denotations.SingleDenotation.matches
// But in case MethodNotAMethodMatch, sym2 must not be a JavaDefined field
def symMatches =
val d1 = sym1.asSeenFrom(self)
val d2 = sym2.asSeenFrom(self)
import Signature.MatchDegree._
d1.signature.matchDegree(d2.signature) match
case FullMatch => true
case NoMatch => false
case MethodNotAMethodMatch =>
!ctx.erasedTypes && !d2.symbol.is(JavaDefinedVal, butNot = Method)
case ParamMatch =>
!ctx.erasedTypes && d1.info.matches(d2.info)

sym1.isType || symMatches
end matches

/** The symbols that can take part in an overriding pair */
private val decls = {
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i9392/J.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class J {
int i = 0;
int i() { return 1; }
}
3 changes: 3 additions & 0 deletions tests/pos/i9392/S.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class S extends J {
override def i(): Int = 2
}