@@ -73,12 +73,6 @@ object Typer {
7373 /** An attachment for GADT constraints that were inferred for a pattern. */
7474 val InferredGadtConstraints = new Property .StickyKey [core.GadtConstraint ]
7575
76- /** A context property that indicates the owner of any expressions to be typed in the context
77- * if that owner is different from the context's owner. Typically, a context with a class
78- * as owner would have a local dummy as ExprOwner value.
79- */
80- private val ExprOwner = new Property .Key [Symbol ]
81-
8276 /** An attachment on a Select node with an `apply` field indicating that the `apply`
8377 * was inserted by the Typer.
8478 */
@@ -2234,18 +2228,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
22342228 /** The context to be used for an annotation of `mdef`.
22352229 * This should be the context enclosing `mdef`, or if `mdef` defines a parameter
22362230 * the context enclosing the owner of `mdef`.
2237- * Furthermore, we need to evaluate annotation arguments in an expression context,
2238- * since classes defined in a such arguments should not be entered into the
2239- * enclosing class.
2231+ * Furthermore, we need to make sure that annotation trees are evaluated
2232+ * with an owner that is not the enclosing class since otherwise locally
2233+ * defined symbols would be entered as class members .
22402234 */
22412235 def annotContext (mdef : untpd.Tree , sym : Symbol )(using Context ): Context =
22422236 def isInner (owner : Symbol ) = owner == sym || sym.is(Param ) && owner == sym.owner
22432237 val outer = ctx.outersIterator.dropWhile(c => isInner(c.owner)).next()
2244- val adjusted = outer.property(ExprOwner ) match {
2245- case Some (exprOwner) if outer.owner.isClass => outer.exprContext(mdef, exprOwner)
2246- case _ => outer
2247- }
2248- def local : FreshContext = adjusted.fresh.setOwner(newLocalDummy(sym.owner))
2238+ def local : FreshContext = outer.fresh.setOwner(newLocalDummy(sym.owner))
22492239 sym.owner.infoOrCompleter match
22502240 case completer : Namer # Completer
22512241 if sym.is(Param ) && completer.completerTypeParams(sym).nonEmpty =>
@@ -2254,7 +2244,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
22542244 // these type parameters. See i12953.scala for a test case.
22552245 local.setScope(newScopeWith(completer.completerTypeParams(sym)* ))
22562246 case _ =>
2257- if outer.owner.isClass then local else adjusted
2247+ if outer.owner.isClass then local else outer
22582248
22592249 def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(using Context ): Unit = {
22602250 // necessary to force annotation trees to be computed.
@@ -3099,10 +3089,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
30993089 case nil =>
31003090 (buf.toList, ctx)
31013091 }
3102- val localCtx = {
3103- val exprOwnerOpt = if (exprOwner == ctx.owner) None else Some (exprOwner)
3104- ctx.withProperty(ExprOwner , exprOwnerOpt)
3105- }
31063092 def finalize (stat : Tree )(using Context ): Tree = stat match {
31073093 case stat : TypeDef if stat.symbol.is(Module ) =>
31083094 val enumContext = enumContexts(stat.symbol.linkedClass)
@@ -3115,7 +3101,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31153101 case _ =>
31163102 stat
31173103 }
3118- val (stats0, finalCtx) = traverse(stats)( using localCtx)
3104+ val (stats0, finalCtx) = traverse(stats)
31193105 val stats1 = stats0.mapConserve(finalize)
31203106 if ctx.owner == exprOwner then checkNoTargetNameConflict(stats1)
31213107 (stats1, finalCtx)
0 commit comments