File tree 2 files changed +14
-4
lines changed
compiler/src/dotty/tools/dotc
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import dotty.tools.dotc.util.SourcePosition;
11
11
12
12
import java .io .OutputStreamWriter
13
13
import java .nio .charset .StandardCharsets .UTF_8
14
+ import dotty .tools .dotc .reporting .CodeAction
14
15
15
16
/** Handles rewriting of Scala2 files to Dotty */
16
17
object Rewrites {
@@ -99,6 +100,14 @@ object Rewrites {
99
100
report.echo(s " [patched file ${source.file.path}] " )
100
101
rewrites.patched(source).writeBack()
101
102
}
103
+
104
+ /** Given a CodeAction take the patches and apply them.
105
+ *
106
+ * @param action The CodeAction containing the patches
107
+ */
108
+ def applyAction (action : CodeAction )(using Context ): Unit =
109
+ action.patches.foreach: actionPatch =>
110
+ patch(actionPatch.srcPos.span, actionPatch.replacement)
102
111
}
103
112
104
113
/** A completely encapsulated class representing rewrite state, used
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ import cc.CheckCaptures
54
54
import config .Config
55
55
56
56
import scala .annotation .constructorOnly
57
+ import dotty .tools .dotc .rewrites .Rewrites
57
58
58
59
object Typer {
59
60
@@ -2946,8 +2947,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2946
2947
if (migrateTo3) {
2947
2948
// Under -rewrite, patch `x _` to `(() => x)`
2948
2949
msg.actions
2949
- .flatMap(_.patches)
2950
- .map(actionPatch => patch(actionPatch.srcPos.span, actionPatch.replacement) )
2950
+ .headOption
2951
+ .foreach( Rewrites .applyAction )
2951
2952
return typed(untpd.Function (Nil , qual), pt)
2952
2953
}
2953
2954
}
@@ -3958,8 +3959,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3958
3959
|| Feature .warnOnMigration(msg, tree.srcPos, version = `3.0`)
3959
3960
&& {
3960
3961
msg.actions
3961
- .flatMap(_.patches)
3962
- .map(actionPatch => patch(actionPatch.srcPos.span, actionPatch.replacement) )
3962
+ .headOption
3963
+ .foreach( Rewrites .applyAction )
3963
3964
true
3964
3965
}
3965
3966
You can’t perform that action at this time.
0 commit comments