Skip to content

Commit c496db7

Browse files
committed
Exempt combinations of Java fields and methods as double defs
Exempt combinations of Java fields and methods from being flagged as double definitions. Java fields don't get a getter, so the pattern int f int f() = f is OK (and quite common).
1 parent e3650c7 commit c496db7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,10 @@ trait Checking {
744744
def checkDecl(decl: Symbol): Unit = {
745745
for (other <- seen(decl.name)) {
746746
typr.println(i"conflict? $decl $other")
747-
if (decl.matches(other)) {
747+
def javaFieldMethodPair =
748+
decl.is(JavaDefined) && other.is(JavaDefined) &&
749+
decl.is(Method) != other.is(Method)
750+
if (decl.matches(other) && !javaFieldMethodPair) {
748751
def doubleDefError(decl: Symbol, other: Symbol): Unit =
749752
if (!decl.info.isErroneous && !other.info.isErroneous)
750753
ctx.error(DoubleDeclaration(decl, other), decl.sourcePos)

tests/pos/i4739.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class TestJava {
2+
int foo;
3+
int foo() {
4+
return this.foo;
5+
}
6+
}

0 commit comments

Comments
 (0)