diff options
author | odersky <odersky@gmail.com> | 2017-02-02 13:48:42 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-02 13:48:42 +1100 |
commit | 64332a794c05cbf21491eaf0bfdf4482a80b1b10 (patch) | |
tree | f10436277073603ddacb3506e8ffcc039a84c54e | |
parent | cca5dd9bd0c8f0d2e5679c81f2c40247a45d7a02 (diff) | |
parent | d64d0a04402a397470081d6a777ecd3cd92e8c43 (diff) | |
download | dotty-64332a794c05cbf21491eaf0bfdf4482a80b1b10.tar.gz dotty-64332a794c05cbf21491eaf0bfdf4482a80b1b10.tar.bz2 dotty-64332a794c05cbf21491eaf0bfdf4482a80b1b10.zip |
Merge pull request #1922 from dotty-staging/fix-#1723
Fix-#1723: Avoid private leaks on completion
5 files changed, 20 insertions, 14 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 51f08a295..ffd594454 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -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 } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index e7c0df1b9..8dff58dea 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -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 = { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 068ef3e4b..6bd8f6d06 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -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) } } @@ -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) } } diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 5c07b7bcf..53ce5555b 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -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))) diff --git a/tests/pos/i1723.scala b/tests/pos/i1723.scala new file mode 100644 index 000000000..75f7cd95c --- /dev/null +++ b/tests/pos/i1723.scala @@ -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 +} |