@@ -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,29 +2228,23 @@ 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
- def annotContext (mdef : untpd.Tree , sym : Symbol )(using Context ): Context = {
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
- var adjusted = outer.property(ExprOwner ) match {
2245
- case Some (exprOwner) if outer.owner.isClass => outer.exprContext(mdef, exprOwner)
2246
- case _ => outer
2247
- }
2238
+ def local : FreshContext = outer.fresh.setOwner(newLocalDummy(sym.owner))
2248
2239
sym.owner.infoOrCompleter match
2249
- case completer : Namer # Completer if sym.is(Param ) =>
2250
- val tparams = completer.completerTypeParams(sym)
2251
- if tparams.nonEmpty then
2252
- // Create a new local context with a dummy owner and a scope containing the
2253
- // type parameters of the enclosing method or class. Thus annotations can see
2254
- // these type parameters. See i12953.scala for a test case.
2255
- val dummyOwner = newLocalDummy(sym.owner)
2256
- adjusted = adjusted.fresh.setOwner(dummyOwner).setScope(newScopeWith(tparams* ))
2240
+ case completer : Namer # Completer
2241
+ if sym.is(Param ) && completer.completerTypeParams(sym).nonEmpty =>
2242
+ // Create a new local context with a dummy owner and a scope containing the
2243
+ // type parameters of the enclosing method or class. Thus annotations can see
2244
+ // these type parameters. See i12953.scala for a test case.
2245
+ local.setScope(newScopeWith(completer.completerTypeParams(sym)* ))
2257
2246
case _ =>
2258
- adjusted
2259
- }
2247
+ if outer.owner.isClass then local else outer
2260
2248
2261
2249
def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(using Context ): Unit = {
2262
2250
// necessary to force annotation trees to be computed.
@@ -3101,10 +3089,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3101
3089
case nil =>
3102
3090
(buf.toList, ctx)
3103
3091
}
3104
- val localCtx = {
3105
- val exprOwnerOpt = if (exprOwner == ctx.owner) None else Some (exprOwner)
3106
- ctx.withProperty(ExprOwner , exprOwnerOpt)
3107
- }
3108
3092
def finalize (stat : Tree )(using Context ): Tree = stat match {
3109
3093
case stat : TypeDef if stat.symbol.is(Module ) =>
3110
3094
val enumContext = enumContexts(stat.symbol.linkedClass)
@@ -3117,7 +3101,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3117
3101
case _ =>
3118
3102
stat
3119
3103
}
3120
- val (stats0, finalCtx) = traverse(stats)( using localCtx)
3104
+ val (stats0, finalCtx) = traverse(stats)
3121
3105
val stats1 = stats0.mapConserve(finalize)
3122
3106
if ctx.owner == exprOwner then checkNoTargetNameConflict(stats1)
3123
3107
(stats1, finalCtx)
0 commit comments