Skip to content

Commit 16b1421

Browse files
committed
Access check secondary constructor parameters
We handle a supercall of a secondary constructor specially, preventing accesses to members of the enclosing class. We need to do the same for parameters of such constructors. We now use two different mechanisms for that: superCallContexts for the super call and checkRefsLegal for the parameters. We should experiment at some point with doing the supercall checks also with chekRefsLegal.
1 parent d2cea4f commit 16b1421

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,10 @@ class Typer extends Namer
14051405
// Overwrite inline body to make sure it is not evaluated twice
14061406
if (sym.isInlineMethod) Inliner.registerInlineInfo(sym, _ => rhs1)
14071407

1408+
if (sym.isConstructor && !sym.isPrimaryConstructor)
1409+
for (param <- tparams1 ::: vparamss1.flatten)
1410+
checkRefsLegal(param, sym.owner, (name, sym) => sym.is(TypeParam), "secondary constructor")
1411+
14081412
assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym)
14091413
//todo: make sure dependent method types do not depend on implicits or by-name params
14101414
}

0 commit comments

Comments
 (0)