@@ -40,7 +40,7 @@ class MetaContextGenPhase(setting: Setting) extends CommonPhase:
40
40
extension (tree : ValOrDefDef )(using Context )
41
41
def needsNewContext : Boolean =
42
42
tree match
43
- case _ : ValDef => true // valdefs always generate new context
43
+ case _ : ValDef => true // valdefs always generate new context
44
44
case dd : DefDef =>
45
45
val sym = tree.symbol
46
46
// defdefs generate new context if they are not inline
@@ -71,7 +71,9 @@ class MetaContextGenPhase(setting: Setting) extends CommonPhase:
71
71
val nameOptTree = mkOptionString(nameOpt)
72
72
val positionTree = srcPos.positionTree
73
73
val docOptTree = mkOptionString(docOpt)
74
- val annotTree = mkList(annotations.map(_.tree))
74
+ // the compiler does not transform the annotations, so we need to do it here.
75
+ // See: https://github.com/scala/scala3/issues/23650
76
+ val annotTree = mkList(annotations.map(a => transformAllDeep(a.tree)))
75
77
tree
76
78
.select(setMetaSym)
77
79
.appliedToArgs(
@@ -112,7 +114,7 @@ class MetaContextGenPhase(setting: Setting) extends CommonPhase:
112
114
t match
113
115
case vd : ValDef if vd.isEmpty || ignoreValDef(vd) => (None , None , Nil )
114
116
case dd : DefDef => (None , None , Nil )
115
- case _ =>
117
+ case _ =>
116
118
(
117
119
Some (t.name.toString.nameCheck(t)),
118
120
t.symbol.docString,
@@ -134,20 +136,32 @@ class MetaContextGenPhase(setting: Setting) extends CommonPhase:
134
136
end match
135
137
end getMetaInfo
136
138
139
+ // The tranformation skips over the named arguments, so we need to transform them here.
140
+ // See: https://github.com/scala/scala3/issues/23650
141
+ def fixApply (tree : Apply )(using Context ): Apply =
142
+ val updatedArgs = tree.args.map {
143
+ case namedArg @ NamedArg (name, arg) =>
144
+ cpy.NamedArg (namedArg)(name = name, arg = transformAllDeep(arg))
145
+ case a => a
146
+ }
147
+ cpy.Apply (tree)(fun = tree.fun, args = updatedArgs)
148
+ end fixApply
149
+
137
150
override def transformApply (tree : Apply )(using Context ): Tree =
151
+ val fixedApply = fixApply(tree)
138
152
val origApply = applyStack.head
139
153
applyStack = applyStack.drop(1 )
140
154
if (
141
- tree .tpe.isParameterless && ! tree .fun.symbol.ignoreMetaContext && ! tree .fun.symbol.forwardMetaContext
155
+ fixedApply .tpe.isParameterless && ! fixedApply .fun.symbol.ignoreMetaContext && ! fixedApply .fun.symbol.forwardMetaContext
142
156
)
143
- tree match
157
+ fixedApply match
144
158
// found a context argument
145
159
case ContextArg (argTree) =>
146
160
treeOwnerApplyMap.get(origApply) match
147
161
case Some (ownerTree, srcPos) =>
148
162
getMetaInfo(ownerTree, srcPos) match
149
163
case Some (metaInfo) =>
150
- tree .replaceArg(argTree, argTree.setMeta(metaInfo))
164
+ fixedApply .replaceArg(argTree, argTree.setMeta(metaInfo))
151
165
case None =>
152
166
val sym = argTree.symbol
153
167
contextDefs.get(sym.fixedFullName) match
@@ -158,17 +172,18 @@ class MetaContextGenPhase(setting: Setting) extends CommonPhase:
158
172
)
159
173
case _ =>
160
174
// do nothing
161
- tree
175
+ fixedApply
162
176
// No owner tree found, so it's anonymous. Yet we may want to apply no new context
163
177
// at all and just keep the propagated context.
164
178
case None =>
165
179
// keeping the propagated context
166
- if (tree .fun.symbol.name.toString.contains(" $" )) tree
180
+ if (fixedApply .fun.symbol.name.toString.contains(" $" )) fixedApply
167
181
// generating a new anonymous context
168
- else tree.replaceArg(argTree, argTree.setMeta(None , origApply.srcPos, None , Nil ))
182
+ else
183
+ fixedApply.replaceArg(argTree, argTree.setMeta(None , origApply.srcPos, None , Nil ))
169
184
end match
170
- case _ => tree
171
- else tree
185
+ case _ => fixedApply
186
+ else fixedApply
172
187
end transformApply
173
188
174
189
override def prepareForBlock (tree : Block )(using Context ): Context =
0 commit comments