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/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