Skip to content

Avoid typing annotations twice #4662

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 26, 2018
Merged
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
16 changes: 10 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,11 @@ class Namer { typer: Typer =>
while (c.owner != target) c = c.outer
c
}

for (annotTree <- untpd.modsDeco(stat).mods.annotations) {
val cls = typedAheadAnnotation(annotTree)(annotCtx)
val cls = typedAheadAnnotationClass(annotTree)(annotCtx)
if (sym.unforcedAnnotation(cls).isEmpty) {
val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree))
val ann = Annotation.deferred(cls, implicit ctx => typedAheadAnnotation(annotTree))
sym.addAnnotation(ann)
if (cls == defn.InlineAnnot && sym.is(Method, butNot = Accessor))
sym.setFlag(Inline)
Expand Down Expand Up @@ -1012,10 +1013,13 @@ class Namer { typer: Typer =>
def typedAheadExpr(tree: Tree, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree =
typedAheadImpl(tree, typer.typed(_, pt)(ctx retractMode Mode.PatternOrTypeBits))

def typedAheadAnnotation(tree: Tree)(implicit ctx: Context): Symbol = tree match {
case Apply(fn, _) => typedAheadAnnotation(fn)
case TypeApply(fn, _) => typedAheadAnnotation(fn)
case Select(qual, nme.CONSTRUCTOR) => typedAheadAnnotation(qual)
def typedAheadAnnotation(tree: Tree)(implicit ctx: Context): tpd.Tree =
typedAheadExpr(tree, defn.AnnotationType)

def typedAheadAnnotationClass(tree: Tree)(implicit ctx: Context): Symbol = tree match {
case Apply(fn, _) => typedAheadAnnotationClass(fn)
case TypeApply(fn, _) => typedAheadAnnotationClass(fn)
case Select(qual, nme.CONSTRUCTOR) => typedAheadAnnotationClass(qual)
case New(tpt) => typedAheadType(tpt).tpe.classSymbol
}

Expand Down