@@ -130,27 +130,25 @@ trait Migrations:
130130 def implicitParams (tree : Tree , tp : MethodOrPoly , pt : FunProto )(using Context ): Unit =
131131 val mversion = mv.ImplicitParamsWithoutUsing
132132 if tp.companion == ImplicitMethodType && pt.applyKind != ApplyKind .Using && pt.args.nonEmpty then
133- val rewriteMsg = Message .rewriteNotice(" This code" , mversion.patchFrom)
133+ // The application can only be rewritten if it uses parentheses syntax.
134+ // See issue #22927 and related tests.
135+ val hasParentheses =
136+ ctx.source.content
137+ .slice(tree.span.end, pt.args.head.span.start)
138+ .exists(_ == '(' )
139+ val rewriteMsg =
140+ if hasParentheses then
141+ Message .rewriteNotice(" This code" , mversion.patchFrom)
142+ else
143+ " "
134144 report.errorOrMigrationWarning(
135145 em """ Implicit parameters should be provided with a `using` clause. $rewriteMsg
136146 |To disable the warning, please use the following option:
137147 | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
138148 | """ ,
139149 pt.args.head.srcPos, mversion)
140- if mversion.needsPatch then
141- // In order to insert a `using`, the application needs to be done with
142- // parentheses syntax. See issue #22927 and related tests.
143- patch(Span (tree.span.end, pt.args.head.span.start), " (using " )
144- // Tentative heuristic: the application was done with parentheses syntax
145- // if there is a `(` between the function and the first argument.
146- val hasParentheses =
147- ctx.source.content
148- .slice(tree.span.end, pt.args.head.span.start)
149- .exists(_ == '(' )
150- if ! hasParentheses then
151- // If the application wasn't done with the parentheses syntax, we need
152- // to add a trailing closing parenthesis.
153- patch(Span (pt.args.head.span.end), " )" )
150+ if hasParentheses && mversion.needsPatch then
151+ patch(Span (pt.args.head.span.start), " using " )
154152 end implicitParams
155153
156154end Migrations
0 commit comments