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