@@ -148,6 +148,9 @@ trait Dynamic {
148
148
untpd.Apply (selectWithTypes, Literal (Constant (name.toString)))
149
149
}
150
150
151
+ extension (tpe : Type )
152
+ def isReflectSelectableTypeRef (using Context ): Boolean = tpe <:< defn.ReflectSelectableTypeRef
153
+
151
154
/** Handle reflection-based dispatch for members of structural types.
152
155
*
153
156
* Given `x.a`, where `x` is of (widened) type `T` (a value type or a nullary method type),
@@ -181,20 +184,25 @@ trait Dynamic {
181
184
val fun @ Select (qual, name) = funPart(tree): @ unchecked
182
185
val vargss = termArgss(tree)
183
186
184
- def handleRepeated (base : untpd.Tree , possiblyCurried : List [List [Tree ]]) =
185
- possiblyCurried.map { args =>
187
+ def handleRepeated (base : untpd.Tree , possiblyCurried : List [List [Tree ]], isReflectSelectable : Boolean ) = {
188
+ val handled = possiblyCurried.map { args =>
186
189
val isRepeated = args.exists(_.tpe.widen.isRepeatedParam)
187
- if isRepeated && qual.tpe <:< defn. ReflectSelectableTypeRef then
190
+ if isRepeated && isReflectSelectable then
188
191
List (untpd.TypedSplice (tpd.repeatedSeq(args, TypeTree (defn.AnyType ))))
189
192
else args.map { t =>
190
193
val clzSym = t.tpe.resultType.classSymbol.asClass
191
- if ValueClasses .isDerivedValueClass(clzSym) && qual.tpe <:< defn. ReflectSelectableTypeRef then
194
+ if ValueClasses .isDerivedValueClass(clzSym) && isReflectSelectable then
192
195
val underlying = ValueClasses .valueClassUnbox(clzSym).asTerm
193
196
tpd.Select (t, underlying.name)
194
197
else
195
198
t
196
199
}.map(untpd.TypedSplice (_))
197
- }.foldLeft(base)((base, args) => untpd.Apply (base, args))
200
+ }
201
+
202
+ if isReflectSelectable
203
+ then untpd.Apply (base, handled.flatten)
204
+ else handled.foldLeft(base)((base, args) => untpd.Apply (base, args))
205
+ }
198
206
199
207
def structuralCall (selectorName : TermName , classOfs : => List [Tree ]) = {
200
208
val selectable = adapt(qual, defn.SelectableClass .typeRef | defn.DynamicClass .typeRef)
@@ -207,7 +215,11 @@ trait Dynamic {
207
215
208
216
val scall =
209
217
if (vargss.isEmpty) base
210
- else handleRepeated(base, vargss)
218
+ else handleRepeated(
219
+ base,
220
+ vargss,
221
+ qual.tpe.isReflectSelectableTypeRef || selectable.tpe.isReflectSelectableTypeRef
222
+ )
211
223
212
224
// If function is an `applyDynamic` that takes a Class* parameter,
213
225
// add `classOfs`.
0 commit comments