Skip to content

Fix #2391: Make child annotation lazy #2392

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 1 commit into from
May 8, 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
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ object Annotations {
apply(defn.AliasAnnot, List(
ref(TermRef.withSigAndDenot(sym.owner.thisType, sym.name, sym.signature, sym))))

def makeChild(sym: Symbol)(implicit ctx: Context) =
deferred(defn.ChildAnnot,
implicit ctx => New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil))
def makeChild(delayedSym: Context => Symbol)(implicit ctx: Context): Annotation = {
def makeChildLater(implicit ctx: Context) = {
val sym = delayedSym(ctx)
New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
}
deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx))
}

def makeChild(sym: Symbol)(implicit ctx: Context): Annotation = makeChild(_ => sym)

def makeSourceFile(path: String)(implicit ctx: Context) =
apply(defn.SourceFileAnnot, Literal(Constant(path)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,13 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
assert(tag == CHILDREN)
val end = readNat() + readIndex
val target = readSymbolRef()
while (readIndex != end)
target.addAnnotation(Annotation.makeChild(readSymbolRef()))
while (readIndex != end) {
val start = readIndex
readNat() // skip reference for now
target.addAnnotation(
Annotation.makeChild(implicit ctx =>
atReadPos(start, () => readSymbolRef())))
}
}

/* Read a reference to a pickled item */
Expand Down
4 changes: 4 additions & 0 deletions tests/new/projection.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class C { type T }
object test {
def x: C#T = ???
}
10 changes: 10 additions & 0 deletions tests/pos/i2391/Containers.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Containers.scala
package foo

trait ParentContainer {
sealed trait Entry
}

class ChildContainer extends ParentContainer {
trait LazyEntry extends Entry
}
6 changes: 6 additions & 0 deletions tests/pos/i2391/User.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// User.scala
package foo

trait User {
type Entry <: ChildContainer#Entry
}