diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 842132270615..9fb22b758f75 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -378,7 +378,6 @@ object Contexts { * - as scope: The parameters of the auxiliary constructor. */ def thisCallArgContext: Context = { - assert(owner.isClassConstructor) val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next() superOrThisCallContext(owner, constrCtx.scope) .setTyperState(typerState) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 5f3449a89080..460a9c21a8b5 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -747,7 +747,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic => * otherwise the current context. */ def argCtx(app: untpd.Tree)(implicit ctx: Context): Context = - if (untpd.isSelfConstrCall(app)) ctx.thisCallArgContext else ctx + if (ctx.owner.isClassConstructor && untpd.isSelfConstrCall(app)) ctx.thisCallArgContext + else ctx /** Typecheck application. Result could be an `Apply` node, * or, if application is an operator assignment, also an `Assign` or diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 814459a672d6..226d40b6f875 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -744,7 +744,10 @@ trait Checking { def checkDecl(decl: Symbol): Unit = { for (other <- seen(decl.name)) { typr.println(i"conflict? $decl $other") - if (decl.matches(other)) { + def javaFieldMethodPair = + decl.is(JavaDefined) && other.is(JavaDefined) && + decl.is(Method) != other.is(Method) + if (decl.matches(other) && !javaFieldMethodPair) { def doubleDefError(decl: Symbol, other: Symbol): Unit = if (!decl.info.isErroneous && !other.info.isErroneous) ctx.error(DoubleDeclaration(decl, other), decl.sourcePos) diff --git a/tests/neg/i5004.scala b/tests/neg/i5004.scala new file mode 100644 index 000000000000..16532bbec69e --- /dev/null +++ b/tests/neg/i5004.scala @@ -0,0 +1,6 @@ +object i0 { +1 match { +def this(): Int // error // error + def this() // error +} // error +} \ No newline at end of file diff --git a/tests/pos/i4739.java b/tests/pos/i4739.java new file mode 100644 index 000000000000..6daa9ff113d5 --- /dev/null +++ b/tests/pos/i4739.java @@ -0,0 +1,6 @@ +public class i4739 { + int foo; + int foo() { + return this.foo; + } +} \ No newline at end of file