Skip to content

Set spans of Child annotations #6752

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
Jun 27, 2019
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
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import config.ScalaVersion
import StdNames._
import dotty.tools.dotc.ast.tpd
import scala.util.Try
import util.Spans.Span

object Annotations {

Expand Down Expand Up @@ -158,16 +159,17 @@ object Annotations {
object Child {

/** A deferred annotation to the result of a given child computation */
def apply(delayedSym: Context => Symbol)(implicit ctx: Context): Annotation = {
def apply(delayedSym: Context => Symbol, span: Span)(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)
.withSpan(span)
}
deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx))
}

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

def unapply(ann: Annotation)(implicit ctx: Context): Option[Symbol] =
if (ann.symbol == defn.ChildAnnot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class ClassfileParser(
ctx.warning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.")
else {
if (!enumClass.is(Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed)
enumClass.addAnnotation(Annotation.Child(sym))
enumClass.addAnnotation(Annotation.Child(sym, NoSpan))
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
readNat() // skip reference for now
target.addAnnotation(
Annotation.Child(implicit ctx =>
atReadPos(start, () => readSymbolRef())))
atReadPos(start, () => readSymbolRef()), NoSpan))
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ class Namer { typer: Typer =>
prefix ::: otherAnnot :: insertInto(rest)
}
case _ =>
Annotation.Child(child) :: annots
Annotation.Child(child, cls.span.startPos) :: annots
}
cls.annotations = insertInto(cls.annotations)
}
Expand Down