Skip to content

Commit 64332a7

Browse files
authored
Merge pull request #1922 from dotty-staging/fix-#1723
Fix-#1723: Avoid private leaks on completion
2 parents cca5dd9 + d64d0a0 commit 64332a7

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
733733
// no longer necessary.
734734
goto(end)
735735
setPos(start, tree)
736-
737-
// This is also done in PostTyper but needs to be redone here
738-
if (!sym.is(SyntheticOrPrivate) && sym.owner.isClass) {
739-
sym.info = Checking.checkNoPrivateLeaks(sym, tree.pos)
740-
}
736+
sym.info = ta.avoidPrivateLeaks(sym, tree.pos)
741737
tree
742738
}
743739

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
107107
private def transformMemberDef(tree: MemberDef)(implicit ctx: Context): Unit = {
108108
val sym = tree.symbol
109109
sym.transformAnnotations(transformAnnot)
110-
// Has to be redone in TreeUnpickler
111-
if (!sym.is(SyntheticOrPrivate) && sym.owner.isClass) {
112-
val info1 = Checking.checkNoPrivateLeaks(sym, tree.pos)
113-
if (info1 ne sym.info)
114-
sym.copySymDenotation(info = info1).installAfter(thisTransformer)
115-
}
116110
}
117111

118112
private def transformSelect(tree: Select, targs: List[Tree])(implicit ctx: Context): Tree = {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,15 @@ class Namer { typer: Typer =>
668668
* to pick up the context at the point where the completer was created.
669669
*/
670670
def completeInCreationContext(denot: SymDenotation): Unit = {
671+
val sym = denot.symbol
671672
original match {
672-
case original: MemberDef => addAnnotations(denot.symbol, original)
673+
case original: MemberDef => addAnnotations(sym, original)
673674
case _ =>
674675
}
675676
addInlineInfo(denot)
676-
denot.info = typeSig(denot.symbol)
677-
Checking.checkWellFormed(denot.symbol)
677+
denot.info = typeSig(sym)
678+
Checking.checkWellFormed(sym)
679+
denot.info = avoidPrivateLeaks(sym, sym.pos)
678680
}
679681
}
680682

@@ -854,6 +856,7 @@ class Namer { typer: Typer =>
854856
if (isDerivedValueClass(cls)) cls.setFlag(Final)
855857
cls.setApplicableFlags(
856858
(NoInitsInterface /: impl.body)((fs, stat) => fs & defKind(stat)))
859+
cls.info = avoidPrivateLeaks(cls, cls.pos)
857860
}
858861
}
859862

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ trait TypeAssigner {
132132
def avoidingType(expr: Tree, bindings: List[Tree])(implicit ctx: Context): Type =
133133
avoid(expr.tpe, localSyms(bindings).filter(_.isTerm))
134134

135+
def avoidPrivateLeaks(sym: Symbol, pos: Position)(implicit ctx: Context): Type =
136+
if (!sym.is(SyntheticOrPrivate) && sym.owner.isClass)
137+
Checking.checkNoPrivateLeaks(sym, pos)
138+
else sym.info
139+
135140
def seqToRepeated(tree: Tree)(implicit ctx: Context): Tree =
136141
Typed(tree, TypeTree(tree.tpe.widen.translateParameterized(defn.SeqClass, defn.RepeatedParamClass)))
137142

tests/pos/i1723.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
private val x: List[Int] = List(1)
3+
def foo = x.head // foo inferred type is this.x.scala$collection$immutable$List$$A
4+
}
5+
6+
class B extends A {
7+
foo
8+
}

0 commit comments

Comments
 (0)