Skip to content

Commit 6fc23da

Browse files
committed
For Java constructors, do not move out to ctx.outer
A Java constructor needs to see the import of the companion object of the class. It is not necessary to move to an outer context because a Java constructor does not have an implementation. scalac also does it this way: see Namers.Namer.createNamer.isConstrParam.
1 parent 9eb65e7 commit 6fc23da

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ class Namer { typer: Typer =>
243243
// different: The former must have the class as owner (because the
244244
// constructor is owned by the class), the latter must not (because
245245
// constructor parameters are interpreted as if they are outside the class).
246-
val cctx = if (tree.name == nme.CONSTRUCTOR) ctx.outer else ctx
246+
// Don't do this for Java constructors because they need to see the import
247+
// of the companion object, and it is not necessary for them because they
248+
// have no implementation.
249+
val cctx = if (tree.name == nme.CONSTRUCTOR && !(tree.mods is JavaDefined)) ctx.outer else ctx
247250

248251
record(ctx.newSymbol(
249252
ctx.owner, name, tree.mods.flags | deferred | method | higherKinded | inSuperCall1,

0 commit comments

Comments
 (0)