Skip to content

Commit 7d2078e

Browse files
ckipp01Kordyjan
authored andcommitted
refactor: make sure the patch logic isn't duplicated
[Cherry-picked e153597]
1 parent a25675d commit 7d2078e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

+14-7
Original file line numberDiff line numberDiff line change
@@ -2877,13 +2877,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28772877
case closure(_, _, _) =>
28782878
case _ =>
28792879
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
2880-
report.errorOrMigrationWarning(
2881-
OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen, tree), tree.srcPos, from = `3.0`
2882-
)
2880+
val msg = OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen, tree)
2881+
report.errorOrMigrationWarning(msg, tree.srcPos, from = `3.0`)
28832882
if (migrateTo3) {
28842883
// Under -rewrite, patch `x _` to `(() => x)`
2885-
patch(Span(tree.span.start), "(() => ")
2886-
patch(Span(qual.span.end, tree.span.end), ")")
2884+
msg.actions
2885+
.flatMap(_.patches)
2886+
.map(actionPatch => patch(actionPatch.srcPos.span, actionPatch.replacement))
28872887
return typed(untpd.Function(Nil, qual), pt)
28882888
}
28892889
}
@@ -3880,10 +3880,17 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38803880
def adaptNoArgsUnappliedMethod(wtp: MethodType, functionExpected: Boolean, arity: Int): Tree = {
38813881
/** Is reference to this symbol `f` automatically expanded to `f()`? */
38823882
def isAutoApplied(sym: Symbol): Boolean =
3883+
lazy val msg = MissingEmptyArgumentList(sym.show, tree)
3884+
38833885
sym.isConstructor
38843886
|| sym.matchNullaryLoosely
3885-
|| Feature.warnOnMigration(MissingEmptyArgumentList(sym.show, tree), tree.srcPos, version = `3.0`)
3886-
&& { patch(tree.span.endPos, "()"); true }
3887+
|| Feature.warnOnMigration(msg, tree.srcPos, version = `3.0`)
3888+
&& {
3889+
msg.actions
3890+
.flatMap(_.patches)
3891+
.map(actionPatch => patch(actionPatch.srcPos.span, actionPatch.replacement))
3892+
true
3893+
}
38873894

38883895
/** If this is a selection prototype of the form `.apply(...): R`, return the nested
38893896
* function prototype `(...)R`. Otherwise `pt`.

0 commit comments

Comments
 (0)