@@ -73,12 +73,6 @@ object Typer {
73
73
/** An attachment for GADT constraints that were inferred for a pattern. */
74
74
val InferredGadtConstraints = new Property .StickyKey [core.GadtConstraint ]
75
75
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
-
82
76
/** An attachment on a Select node with an `apply` field indicating that the `apply`
83
77
* was inserted by the Typer.
84
78
*/
@@ -2234,18 +2228,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2234
2228
/** The context to be used for an annotation of `mdef`.
2235
2229
* This should be the context enclosing `mdef`, or if `mdef` defines a parameter
2236
2230
* 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 .
2240
2234
*/
2241
2235
def annotContext (mdef : untpd.Tree , sym : Symbol )(using Context ): Context =
2242
2236
def isInner (owner : Symbol ) = owner == sym || sym.is(Param ) && owner == sym.owner
2243
2237
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))
2249
2239
sym.owner.infoOrCompleter match
2250
2240
case completer : Namer # Completer
2251
2241
if sym.is(Param ) && completer.completerTypeParams(sym).nonEmpty =>
@@ -2254,7 +2244,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2254
2244
// these type parameters. See i12953.scala for a test case.
2255
2245
local.setScope(newScopeWith(completer.completerTypeParams(sym)* ))
2256
2246
case _ =>
2257
- if outer.owner.isClass then local else adjusted
2247
+ if outer.owner.isClass then local else outer
2258
2248
2259
2249
def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(using Context ): Unit = {
2260
2250
// necessary to force annotation trees to be computed.
@@ -3099,10 +3089,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3099
3089
case nil =>
3100
3090
(buf.toList, ctx)
3101
3091
}
3102
- val localCtx = {
3103
- val exprOwnerOpt = if (exprOwner == ctx.owner) None else Some (exprOwner)
3104
- ctx.withProperty(ExprOwner , exprOwnerOpt)
3105
- }
3106
3092
def finalize (stat : Tree )(using Context ): Tree = stat match {
3107
3093
case stat : TypeDef if stat.symbol.is(Module ) =>
3108
3094
val enumContext = enumContexts(stat.symbol.linkedClass)
@@ -3115,7 +3101,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3115
3101
case _ =>
3116
3102
stat
3117
3103
}
3118
- val (stats0, finalCtx) = traverse(stats)( using localCtx)
3104
+ val (stats0, finalCtx) = traverse(stats)
3119
3105
val stats1 = stats0.mapConserve(finalize)
3120
3106
if ctx.owner == exprOwner then checkNoTargetNameConflict(stats1)
3121
3107
(stats1, finalCtx)
0 commit comments