Skip to content

Fix-#1723: Avoid private leaks on completion #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
// no longer necessary.
goto(end)
setPos(start, tree)

// This is also done in PostTyper but needs to be redone here
if (!sym.is(SyntheticOrPrivate) && sym.owner.isClass) {
sym.info = Checking.checkNoPrivateLeaks(sym, tree.pos)
}
sym.info = ta.avoidPrivateLeaks(sym, tree.pos)
tree
}

Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
private def transformMemberDef(tree: MemberDef)(implicit ctx: Context): Unit = {
val sym = tree.symbol
sym.transformAnnotations(transformAnnot)
// Has to be redone in TreeUnpickler
if (!sym.is(SyntheticOrPrivate) && sym.owner.isClass) {
val info1 = Checking.checkNoPrivateLeaks(sym, tree.pos)
if (info1 ne sym.info)
sym.copySymDenotation(info = info1).installAfter(thisTransformer)
}
}

private def transformSelect(tree: Select, targs: List[Tree])(implicit ctx: Context): Tree = {
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -668,13 +668,15 @@ class Namer { typer: Typer =>
* to pick up the context at the point where the completer was created.
*/
def completeInCreationContext(denot: SymDenotation): Unit = {
val sym = denot.symbol
original match {
case original: MemberDef => addAnnotations(denot.symbol, original)
case original: MemberDef => addAnnotations(sym, original)
case _ =>
}
addInlineInfo(denot)
denot.info = typeSig(denot.symbol)
Checking.checkWellFormed(denot.symbol)
denot.info = typeSig(sym)
Checking.checkWellFormed(sym)
denot.info = avoidPrivateLeaks(sym, sym.pos)
}
}

Expand Down Expand Up @@ -854,6 +856,7 @@ class Namer { typer: Typer =>
if (isDerivedValueClass(cls)) cls.setFlag(Final)
cls.setApplicableFlags(
(NoInitsInterface /: impl.body)((fs, stat) => fs & defKind(stat)))
cls.info = avoidPrivateLeaks(cls, cls.pos)
}
}

Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ trait TypeAssigner {
def avoidingType(expr: Tree, bindings: List[Tree])(implicit ctx: Context): Type =
avoid(expr.tpe, localSyms(bindings).filter(_.isTerm))

def avoidPrivateLeaks(sym: Symbol, pos: Position)(implicit ctx: Context): Type =
if (!sym.is(SyntheticOrPrivate) && sym.owner.isClass)
Checking.checkNoPrivateLeaks(sym, pos)
else sym.info

def seqToRepeated(tree: Tree)(implicit ctx: Context): Tree =
Typed(tree, TypeTree(tree.tpe.widen.translateParameterized(defn.SeqClass, defn.RepeatedParamClass)))

Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i1723.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class A {
private val x: List[Int] = List(1)
def foo = x.head // foo inferred type is this.x.scala$collection$immutable$List$$A
}

class B extends A {
foo
}