Skip to content

Commit ffd28b3

Browse files
committed
Check for InSuperCall mode
1 parent d83d09d commit ffd28b3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,11 @@ class Typer extends Namer
396396
}
397397
else if (name.toTermName == nme.ERROR)
398398
UnspecifiedErrorType
399-
else if (ctx.owner.isConstructor && ctx.owner.owner.unforcedDecls.lookup(tree.name).exists) {
400-
// If the field existed but was not found we assume that
401-
// we where in the context of an argument of the super constructor
402-
errorType(ex"$tree is not accessible from super constructor arguments", tree.pos)
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)
403404
} else
404405
errorType(new MissingIdent(tree, kind, name.show), tree.pos)
405406

compiler/test-resources/repl/i2631

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

0 commit comments

Comments
 (0)