Skip to content

Commit 3fca1a8

Browse files
committed
Fix #2391: Make child annotation lazy
Make child annotations compute their symbols lazily when unpickling from Scala2
1 parent 5093126 commit 3fca1a8

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,15 @@ object Annotations {
141141
apply(defn.AliasAnnot, List(
142142
ref(TermRef.withSigAndDenot(sym.owner.thisType, sym.name, sym.signature, sym))))
143143

144-
def makeChild(sym: Symbol)(implicit ctx: Context) =
145-
deferred(defn.ChildAnnot,
146-
implicit ctx => New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil))
144+
def makeChild(delayedSym: Context => Symbol)(implicit ctx: Context): Annotation = {
145+
def makeChildLater(implicit ctx: Context) = {
146+
val sym = delayedSym(ctx)
147+
New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
148+
}
149+
deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx))
150+
}
151+
152+
def makeChild(sym: Symbol)(implicit ctx: Context): Annotation = makeChild(_ => sym)
147153

148154
def makeSourceFile(path: String)(implicit ctx: Context) =
149155
apply(defn.SourceFileAnnot, Literal(Constant(path)))

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,13 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
829829
assert(tag == CHILDREN)
830830
val end = readNat() + readIndex
831831
val target = readSymbolRef()
832-
while (readIndex != end)
833-
target.addAnnotation(Annotation.makeChild(readSymbolRef()))
832+
while (readIndex != end) {
833+
val start = readIndex
834+
readNat() // skip reference for now
835+
target.addAnnotation(
836+
Annotation.makeChild(implicit ctx =>
837+
atReadPos(start, () => readSymbolRef())))
838+
}
834839
}
835840

836841
/* Read a reference to a pickled item */

tests/new/projection.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class C { type T }
2+
object test {
3+
def x: C#T = ???
4+
}

tests/pos/i2391/Containers.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Containers.scala
2+
package foo
3+
4+
trait ParentContainer {
5+
sealed trait Entry
6+
}
7+
8+
class ChildContainer extends ParentContainer {
9+
trait LazyEntry extends Entry
10+
}

tests/pos/i2391/User.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// User.scala
2+
package foo
3+
4+
trait User {
5+
type Entry <: ChildContainer#Entry
6+
}

0 commit comments

Comments
 (0)