File tree Expand file tree Collapse file tree 4 files changed +43
-3
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -976,8 +976,22 @@ object Denotations {
976
976
case FullMatch =>
977
977
true
978
978
case MethodNotAMethodMatch =>
979
- // Java allows defining both a field and a zero-parameter method with the same name
980
- ! ctx.erasedTypes && ! (symbol.is(JavaDefined ) && other.symbol.is(JavaDefined ))
979
+ ! ctx.erasedTypes && {
980
+ val isJava = symbol.is(JavaDefined )
981
+ val otherIsJava = other.symbol.is(JavaDefined )
982
+ // A Scala zero-parameter method and a Scala non-method always match.
983
+ if ! isJava && ! otherIsJava then
984
+ true
985
+ // Java allows defining both a field and a zero-parameter method with the same name,
986
+ // so they must not match.
987
+ else if isJava && otherIsJava then
988
+ false
989
+ // A Java field never matches a Scala method.
990
+ else if isJava then
991
+ symbol.is(Method )
992
+ else // otherIsJava
993
+ other.symbol.is(Method )
994
+ }
981
995
case ParamMatch =>
982
996
// The signatures do not tell us enough to be sure about matching
983
997
! ctx.erasedTypes && info.matches(other.info)
Original file line number Diff line number Diff line change 1
1
class B extends A {
2
2
override val foo : String = " B" // error
3
- }
3
+ }
Original file line number Diff line number Diff line change
1
+ package pkg ;
2
+
3
+ public class J {
4
+ int i = 0 ;
5
+ public int i () { return 1 ; }
6
+ }
Original file line number Diff line number Diff line change
1
+ class S1 extends pkg.J {
2
+ override def i (): Int = 2
3
+ }
4
+
5
+ // Unlike Scala 2 this doesn't compile, because this override of `i()`
6
+ // also matches the non-overridable field `i`.
7
+ // class S2 extends pkg.J {
8
+ // override def i: Int = 2
9
+ // }
10
+
11
+ object Test {
12
+ val s1 = new S1
13
+
14
+ val i1 = s1.i
15
+ val i2 = s1.i()
16
+
17
+ // val s2 = new S2
18
+
19
+ // val i3 = s2.i
20
+ }
You can’t perform that action at this time.
0 commit comments