diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 077bb05b63a9..70e31d2ffc02 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -396,7 +396,12 @@ class Typer extends Namer } else if (name.toTermName == nme.ERROR) UnspecifiedErrorType - else + else if (ctx.owner.isConstructor && ctx.mode.is(Mode.InSuperCall) && + ctx.owner.owner.unforcedDecls.lookup(tree.name).exists) { + // When InSuperCall mode and in a constructor we are in the arguments + // of a this(...) constructor call + errorType(ex"$tree is not accessible from constructor arguments", tree.pos) + } else errorType(new MissingIdent(tree, kind, name.show), tree.pos) val tree1 = ownType match { diff --git a/compiler/test-resources/repl/i2631 b/compiler/test-resources/repl/i2631 new file mode 100644 index 000000000000..f68b430d829d --- /dev/null +++ b/compiler/test-resources/repl/i2631 @@ -0,0 +1,4 @@ +scala> class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } } +1 | class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } } + | ^^^ + | foo is not accessible from constructor arguments \ No newline at end of file