@@ -1339,20 +1339,26 @@ class Typer extends Namer
1339
1339
assignType(cpy.Alternative (tree)(trees1), trees1)
1340
1340
}
1341
1341
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
+
1342
1358
def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(implicit ctx : Context ): Unit = {
1343
1359
// necessary to force annotation trees to be computed.
1344
1360
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)
1356
1362
// necessary in order to mark the typed ahead annotations as definitely typed:
1357
1363
untpd.modsDeco(mdef).mods.annotations.foreach(typedAnnotation(_)(annotCtx))
1358
1364
}
0 commit comments