Skip to content

Commit e8e2385

Browse files
committed
Set spans of Child annotations
This is necessary to prevent unstability of pickled positions under -Ytest-pickler
1 parent 866ac14 commit e8e2385

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import config.ScalaVersion
66
import StdNames._
77
import dotty.tools.dotc.ast.tpd
88
import scala.util.Try
9+
import util.Spans.Span
910

1011
object Annotations {
1112

@@ -158,16 +159,17 @@ object Annotations {
158159
object Child {
159160

160161
/** A deferred annotation to the result of a given child computation */
161-
def apply(delayedSym: Context => Symbol)(implicit ctx: Context): Annotation = {
162+
def apply(delayedSym: Context => Symbol, span: Span)(implicit ctx: Context): Annotation = {
162163
def makeChildLater(implicit ctx: Context) = {
163164
val sym = delayedSym(ctx)
164165
New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
166+
.withSpan(span)
165167
}
166168
deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx))
167169
}
168170

169171
/** A regular, non-deferred Child annotation */
170-
def apply(sym: Symbol)(implicit ctx: Context): Annotation = apply(_ => sym)
172+
def apply(sym: Symbol, span: Span)(implicit ctx: Context): Annotation = apply(_ => sym, span)
171173

172174
def unapply(ann: Annotation)(implicit ctx: Context): Option[Symbol] =
173175
if (ann.symbol == defn.ChildAnnot) {

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class ClassfileParser(
277277
ctx.warning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.")
278278
else {
279279
if (!enumClass.is(Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed)
280-
enumClass.addAnnotation(Annotation.Child(sym))
280+
enumClass.addAnnotation(Annotation.Child(sym, NoSpan))
281281
}
282282
}
283283
} finally {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
835835
readNat() // skip reference for now
836836
target.addAnnotation(
837837
Annotation.Child(implicit ctx =>
838-
atReadPos(start, () => readSymbolRef())))
838+
atReadPos(start, () => readSymbolRef()), NoSpan))
839839
}
840840
}
841841

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ class Namer { typer: Typer =>
523523
prefix ::: otherAnnot :: insertInto(rest)
524524
}
525525
case _ =>
526-
Annotation.Child(child) :: annots
526+
Annotation.Child(child, cls.span.startPos) :: annots
527527
}
528528
cls.annotations = insertInto(cls.annotations)
529529
}

0 commit comments

Comments
 (0)