Skip to content

Commit 0c35b8f

Browse files
committed
Address review comments
1 parent 0500452 commit 0c35b8f

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,7 @@ class Namer { typer: Typer =>
748748

749749
protected def addAnnotations(sym: Symbol): Unit = original match {
750750
case original: untpd.MemberDef =>
751-
var hasInlineAnnot = false
752-
lazy val annotCtx =
753-
if (sym.is(Param)) ctx.outersIterator.dropWhile(_.owner == sym.owner).next
754-
else ctx
751+
lazy val annotCtx = annotContext(original, sym)
755752
for (annotTree <- untpd.modsDeco(original).mods.annotations) {
756753
val cls = typedAheadAnnotationClass(annotTree)(annotCtx)
757754
val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree))

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,20 +1339,26 @@ class Typer extends Namer
13391339
assignType(cpy.Alternative(tree)(trees1), trees1)
13401340
}
13411341

1342+
/** The context to be used for an annotation of `mdef`.
1343+
* This should be the context enclosing `mdef`, or if `mdef` defines a parameter
1344+
* the context enclosing the owner of `mdef`.
1345+
* Furthermore, we need to evaluate annotation arguments in an expression context,
1346+
* since classes defined in a such arguments should not be entered into the
1347+
* enclosing class.
1348+
*/
1349+
def annotContext(mdef: untpd.Tree, sym: Symbol)(implicit ctx: Context): Context = {
1350+
def isInner(owner: Symbol) = owner == sym || sym.is(Param) && owner == sym.owner
1351+
val c = ctx.outersIterator.dropWhile(c => isInner(c.owner)).next()
1352+
c.property(ExprOwner) match {
1353+
case Some(exprOwner) if c.owner.isClass => c.exprContext(mdef, exprOwner)
1354+
case _ => c
1355+
}
1356+
}
1357+
13421358
def completeAnnotations(mdef: untpd.MemberDef, sym: Symbol)(implicit ctx: Context): Unit = {
13431359
// necessary to force annotation trees to be computed.
13441360
sym.annotations.foreach(_.ensureCompleted)
1345-
lazy val annotCtx = {
1346-
val c = ctx.outersIterator.dropWhile(_.owner == sym).next()
1347-
c.property(ExprOwner) match {
1348-
case Some(exprOwner) if c.owner.isClass =>
1349-
// We need to evaluate annotation arguments in an expression context, since
1350-
// classes defined in a such arguments should not be entered into the
1351-
// enclosing class.
1352-
c.exprContext(mdef, exprOwner)
1353-
case _ => c
1354-
}
1355-
}
1361+
lazy val annotCtx = annotContext(mdef, sym)
13561362
// necessary in order to mark the typed ahead annotations as definitely typed:
13571363
untpd.modsDeco(mdef).mods.annotations.foreach(typedAnnotation(_)(annotCtx))
13581364
}

0 commit comments

Comments
 (0)