@@ -27,7 +27,7 @@ import EtaExpansion.etaExpand
27
27
import dotty .tools .dotc .transform .Erasure .Boxing
28
28
import util .Positions ._
29
29
import util .common ._
30
- import util .SourcePosition
30
+ import util .{ SourcePosition , Property }
31
31
import collection .mutable
32
32
import annotation .tailrec
33
33
import Implicits ._
@@ -57,6 +57,8 @@ object Typer {
57
57
def assertPositioned (tree : untpd.Tree )(implicit ctx : Context ) =
58
58
if (! tree.isEmpty && ! tree.isInstanceOf [untpd.TypedSplice ] && ctx.typerState.isGlobalCommittable)
59
59
assert(tree.pos.exists, s " position not set for $tree # ${tree.uniqueId}" )
60
+
61
+ private val ExprOwner = new Property .Key [Symbol ]
60
62
}
61
63
62
64
class Typer extends Namer with TypeAssigner with Applications with Implicits with Dynamic with Checking with Docstrings {
@@ -1133,7 +1135,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1133
1135
def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(implicit ctx : Context ): Unit = {
1134
1136
// necessary to force annotation trees to be computed.
1135
1137
sym.annotations.foreach(_.ensureCompleted)
1136
- val annotCtx = ctx.outersIterator.dropWhile(_.owner == sym).next
1138
+ lazy val annotCtx = {
1139
+ val c = ctx.outersIterator.dropWhile(_.owner == sym).next
1140
+ c.property(ExprOwner ) match {
1141
+ case Some (exprOwner) if c.owner.isClass => c.exprContext(mdef, exprOwner)
1142
+ case None => c
1143
+ }
1144
+ }
1137
1145
// necessary in order to mark the typed ahead annotations as definitely typed:
1138
1146
untpd.modsDeco(mdef).mods.annotations.foreach(typedAnnotation(_)(annotCtx))
1139
1147
}
@@ -1552,7 +1560,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1552
1560
case nil =>
1553
1561
buf.toList
1554
1562
}
1555
- traverse(stats)
1563
+ val localCtx = {
1564
+ val exprOwnerOpt = if (exprOwner == ctx.owner) None else Some (exprOwner)
1565
+ ctx.withProperty(ExprOwner , exprOwnerOpt)
1566
+ }
1567
+ traverse(stats)(localCtx)
1556
1568
}
1557
1569
1558
1570
/** Given an inline method `mdef`, the method rewritten so that its body
0 commit comments