Skip to content

Commit 72e9c8e

Browse files
Merge pull request #3802 from dotty-staging/fix-#2631
Fix #2631: Add custom error message
2 parents 618e5de + ffd28b3 commit 72e9c8e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,12 @@ class Typer extends Namer
396396
}
397397
else if (name.toTermName == nme.ERROR)
398398
UnspecifiedErrorType
399-
else
399+
else if (ctx.owner.isConstructor && ctx.mode.is(Mode.InSuperCall) &&
400+
ctx.owner.owner.unforcedDecls.lookup(tree.name).exists) {
401+
// When InSuperCall mode and in a constructor we are in the arguments
402+
// of a this(...) constructor call
403+
errorType(ex"$tree is not accessible from constructor arguments", tree.pos)
404+
} else
400405
errorType(new MissingIdent(tree, kind, name.show), tree.pos)
401406

402407
val tree1 = ownType match {

compiler/test-resources/repl/i2631

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scala> class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
2+
1 | class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
3+
| ^^^
4+
| foo is not accessible from constructor arguments

0 commit comments

Comments
 (0)