File tree 6 files changed +40
-11
lines changed
test/dotty/tools/dotc/reporting
6 files changed +40
-11
lines changed Original file line number Diff line number Diff line change @@ -424,12 +424,17 @@ trait NoDisambiguation extends Message:
424
424
withoutDisambiguation()
425
425
426
426
/** The fallback `Message` containing no explanation and having no `kind` */
427
- final class NoExplanation (msgFn : Context ?=> String )(using Context ) extends Message (ErrorMessageID .NoExplanationID ) {
427
+ final class NoExplanation (msgFn : Context ?=> String , actions : List [ CodeAction ] = List .empty )(using Context ) extends Message (ErrorMessageID .NoExplanationID ) {
428
428
def msg (using Context ): String = msgFn
429
429
def explain (using Context ): String = " "
430
430
val kind : MessageKind = MessageKind .NoKind
431
431
432
+ override def actions (using Context ): List [CodeAction ] = actions
433
+
432
434
override def toString (): String = msg
435
+
436
+ def withActions (actions : CodeAction * ): NoExplanation =
437
+ new NoExplanation (msgFn, actions.toList)
433
438
}
434
439
435
440
/** 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
21
21
import rewrites .Rewrites .patch
22
22
import util .Spans .Span
23
23
import rewrites .Rewrites
24
+ import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
25
+ import dotty .tools .dotc .util .SourcePosition
24
26
25
27
/** A utility trait containing source-dependent deprecation messages
26
28
* and migrations.
@@ -139,14 +141,23 @@ trait Migrations:
139
141
val rewriteMsg =
140
142
if hasParentheses then
141
143
Message .rewriteNotice(" This code" , mversion.patchFrom)
142
- else
143
- " "
144
- report.errorOrMigrationWarning(
144
+ else " "
145
+ val message =
145
146
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:
147
148
| "-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
+ )
150
161
if hasParentheses && mversion.needsPatch then
151
162
patch(Span (pt.args.head.span.start), " using " )
152
163
end implicitParams
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ class CodeActionTest extends DottyTest:
54
54
|""" .stripMargin
55
55
)
56
56
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
+
57
70
@ Test def insertMissingCases =
58
71
checkCodeAction(
59
72
code =
Original file line number Diff line number Diff line change 3
3
| ^
4
4
| Implicit parameters should be provided with a `using` clause.
5
5
| 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:
7
7
| "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
Original file line number Diff line number Diff line change 3
3
| ^
4
4
| Implicit parameters should be provided with a `using` clause.
5
5
| 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:
7
7
| "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
Original file line number Diff line number Diff line change 3
3
| ^^^^^^^^
4
4
| Implicit parameters should be provided with a `using` clause.
5
5
| 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:
7
7
| "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
8
8
-- Warning: tests/warn/i22731.scala:7:6 --------------------------------------------------------------------------------
9
9
7 | foo { () => 43 } // warn
10
10
| ^^^^^^^^^^^^
11
11
| 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:
13
13
| "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
You can’t perform that action at this time.
0 commit comments