@@ -1110,6 +1110,21 @@ trait Applications extends Compatibility {
1110
1110
then originalProto.tupledDual
1111
1111
else originalProto
1112
1112
1113
+ /* TODO (*) Get rid of this case. It is still syntax-based, therefore unreliable.
1114
+ * It is necessary for things like `someDynamic[T](...)`, because in that case,
1115
+ * somehow typedFunPart returns a tree that was typed as `TryDynamicCallType`,
1116
+ * so clearly with the view that an apply insertion was necessary, but doesn't
1117
+ * actually insert the apply!
1118
+ * This is probably something wrong in apply insertion, but I (@sjrd) am out of
1119
+ * my depth there.
1120
+ * In the meantime, this makes tests pass.
1121
+ */
1122
+ def isInsertedApply = fun1 match
1123
+ case Select (_, nme.apply) => fun1.span.isSynthetic
1124
+ case TypeApply (sel @ Select (_, nme.apply), _) => sel.span.isSynthetic
1125
+ case TypeApply (fun, _) => ! fun.isInstanceOf [Select ] // (*) see explanatory comment
1126
+ case _ => false
1127
+
1113
1128
/** Type application where arguments come from prototype, and no implicits are inserted */
1114
1129
def simpleApply (fun1 : Tree , proto : FunProto )(using Context ): Tree =
1115
1130
methPart(fun1).tpe match {
@@ -1186,6 +1201,11 @@ trait Applications extends Compatibility {
1186
1201
case _ => ()
1187
1202
1188
1203
def maybePatchBadParensForImplicit (failedState : TyperState )(using Context ): Boolean =
1204
+ def rewrite (): Unit =
1205
+ val replace =
1206
+ if isInsertedApply then " .apply" // x() -> x.apply
1207
+ else " " // f() -> f where fun1.span.end == tree.span.point
1208
+ rewrites.Rewrites .patch(tree.span.withStart(fun1.span.end), replace)
1189
1209
var retry = false
1190
1210
failedState.reporter.mapBufferedMessages: dia =>
1191
1211
dia match
@@ -1195,7 +1215,7 @@ trait Applications extends Compatibility {
1195
1215
val mv = MigrationVersion .ImplicitParamsWithoutUsing
1196
1216
if mv.needsPatch then
1197
1217
retry = true
1198
- rewrites. Rewrites .patch(tree.span.withStart(tree.span.point), " " ) // f() -> f
1218
+ rewrite()
1199
1219
Diagnostic .Warning (err.msg, err.pos)
1200
1220
else err
1201
1221
case _ => err
@@ -1205,21 +1225,6 @@ trait Applications extends Compatibility {
1205
1225
val result = fun1.tpe match {
1206
1226
case err : ErrorType => cpy.Apply (tree)(fun1, proto.typedArgs()).withType(err)
1207
1227
case TryDynamicCallType =>
1208
- val isInsertedApply = fun1 match {
1209
- case Select (_, nme.apply) => fun1.span.isSynthetic
1210
- case TypeApply (sel @ Select (_, nme.apply), _) => sel.span.isSynthetic
1211
- /* TODO Get rid of this case. It is still syntax-based, therefore unreliable.
1212
- * It is necessary for things like `someDynamic[T](...)`, because in that case,
1213
- * somehow typedFunPart returns a tree that was typed as `TryDynamicCallType`,
1214
- * so clearly with the view that an apply insertion was necessary, but doesn't
1215
- * actually insert the apply!
1216
- * This is probably something wrong in apply insertion, but I (@sjrd) am out of
1217
- * my depth there.
1218
- * In the meantime, this makes tests pass.
1219
- */
1220
- case TypeApply (fun, _) => ! fun.isInstanceOf [Select ]
1221
- case _ => false
1222
- }
1223
1228
val tree1 = fun1 match
1224
1229
case Select (_, nme.apply) => tree
1225
1230
case _ => untpd.Apply (fun1, tree.args)
0 commit comments