Skip to content

Commit 2b0e4a1

Browse files
authored
Merge pull request #5931 from dotty-staging/fix-#4739
Fix #4739: Exempt combinations of Java fields and methods as double defs
2 parents 6cb65d2 + 5e9f086 commit 2b0e4a1

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 i4739 {
2+
int foo;
3+
int foo() {
4+
return this.foo;
5+
}
6+
}

0 commit comments

Comments
 (0)