@@ -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 {
@@ -1135,7 +1137,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1135
1137
def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(implicit ctx : Context ): Unit = {
1136
1138
// necessary to force annotation trees to be computed.
1137
1139
sym.annotations.foreach(_.ensureCompleted)
1138
- val annotCtx = ctx.outersIterator.dropWhile(_.owner == sym).next
1140
+ lazy val annotCtx = {
1141
+ val c = ctx.outersIterator.dropWhile(_.owner == sym).next
1142
+ c.property(ExprOwner ) match {
1143
+ case Some (exprOwner) if c.owner.isClass => c.exprContext(mdef, exprOwner)
1144
+ case None => c
1145
+ }
1146
+ }
1139
1147
// necessary in order to mark the typed ahead annotations as definitely typed:
1140
1148
untpd.modsDeco(mdef).mods.annotations.foreach(typedAnnotation(_)(annotCtx))
1141
1149
}
@@ -1541,7 +1549,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1541
1549
case nil =>
1542
1550
buf.toList
1543
1551
}
1544
- traverse(stats)
1552
+ val localCtx = {
1553
+ val exprOwnerOpt = if (exprOwner == ctx.owner) None else Some (exprOwner)
1554
+ ctx.withProperty(ExprOwner , exprOwnerOpt)
1555
+ }
1556
+ traverse(stats)(localCtx)
1545
1557
}
1546
1558
1547
1559
/** Given an inline method `mdef`, the method rewritten so that its body
0 commit comments