File tree Expand file tree Collapse file tree 6 files changed +40
-11
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 6 files changed +40
-11
lines changed Original file line number Diff line number Diff line change @@ -487,12 +487,17 @@ trait NoDisambiguation extends Message:
487487 withoutDisambiguation()
488488
489489/** The fallback `Message` containing no explanation and having no `kind` */
490- final class NoExplanation (msgFn : Context ?=> String )(using Context ) extends Message (ErrorMessageID .NoExplanationID ) {
490+ final class NoExplanation (msgFn : Context ?=> String , actions : List [ CodeAction ] = List .empty )(using Context ) extends Message (ErrorMessageID .NoExplanationID ) {
491491 def msg (using Context ): String = msgFn
492492 def explain (using Context ): String = " "
493493 val kind : MessageKind = MessageKind .NoKind
494494
495+ override def actions (using Context ): List [CodeAction ] = actions
496+
495497 override def toString (): String = msg
498+
499+ def withActions (actions : CodeAction * ): NoExplanation =
500+ new NoExplanation (msgFn, actions.toList)
496501}
497502
498503/** The extractor for `NoExplanation` can be used to check whether any error
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ import NameKinds.ContextBoundParamName
2121import rewrites .Rewrites .patch
2222import util .Spans .Span
2323import rewrites .Rewrites
24+ import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
25+ import dotty .tools .dotc .util .SourcePosition
2426
2527/** A utility trait containing source-dependent deprecation messages
2628 * and migrations.
@@ -139,14 +141,23 @@ trait Migrations:
139141 val rewriteMsg =
140142 if hasParentheses then
141143 Message .rewriteNotice(" This code" , mversion.patchFrom)
142- else
143- " "
144- report.errorOrMigrationWarning(
144+ else " "
145+ val message =
145146 em """ Implicit parameters should be provided with a `using` clause. $rewriteMsg
146- |To disable the warning, please use the following option:
147+ |To disable the warning, please use the following option:
147148 | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
148- | """ ,
149- pt.args.head.srcPos, mversion)
149+ | """
150+ val codeAction = CodeAction (
151+ title = " Add `using` clause" ,
152+ description = None ,
153+ patches = List (ActionPatch (pt.args.head.startPos.sourcePos, " using " ))
154+ )
155+ val withActions = message.withActions(codeAction)
156+ report.errorOrMigrationWarning(
157+ withActions,
158+ pt.args.head.srcPos,
159+ mversion
160+ )
150161 if hasParentheses && mversion.needsPatch then
151162 patch(Span (pt.args.head.span.start), " using " )
152163 end implicitParams
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ class CodeActionTest extends DottyTest:
5454 |""" .stripMargin
5555 )
5656
57+ @ Test def addUsingClause =
58+ checkCodeAction(
59+ """ |object Test:
60+ | def foo(implicit a: Int) = a
61+ | foo(123)
62+ |""" .stripMargin,
63+ " Add `using` clause" ,
64+ """ |object Test:
65+ | def foo(implicit a: Int) = a
66+ | foo(using 123)
67+ |""" .stripMargin
68+ )
69+
5770 @ Test def insertMissingCases =
5871 checkCodeAction(
5972 code =
Original file line number Diff line number Diff line change 33 | ^
44 | Implicit parameters should be provided with a `using` clause.
55 | This code can be rewritten automatically under -rewrite -source 3.7-migration.
6- | To disable the warning, please use the following option:
6+ | To disable the warning, please use the following option:
77 | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
Original file line number Diff line number Diff line change 33 | ^
44 | Implicit parameters should be provided with a `using` clause.
55 | This code can be rewritten automatically under -rewrite -source 3.7-migration.
6- | To disable the warning, please use the following option:
6+ | To disable the warning, please use the following option:
77 | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
Original file line number Diff line number Diff line change 33 | ^^^^^^^^
44 | Implicit parameters should be provided with a `using` clause.
55 | This code can be rewritten automatically under -rewrite -source 3.7-migration.
6- | To disable the warning, please use the following option:
6+ | To disable the warning, please use the following option:
77 | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
88-- Warning: tests/warn/i22731.scala:7:6 --------------------------------------------------------------------------------
997 | foo { () => 43 } // warn
1010 | ^^^^^^^^^^^^
1111 | Implicit parameters should be provided with a `using` clause.
12- | To disable the warning, please use the following option:
12+ | To disable the warning, please use the following option:
1313 | "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
You can’t perform that action at this time.
0 commit comments