Skip to content

Commit

Permalink
refactor: make sure the patch logic isn't duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
ckipp01 committed Jul 6, 2023
1 parent 794216a commit e153597
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2941,13 +2941,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case closure(_, _, _) =>
case _ =>
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
report.errorOrMigrationWarning(
OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen, tree), tree.srcPos, from = `3.0`
)
val msg = OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen, tree)
report.errorOrMigrationWarning(msg, tree.srcPos, from = `3.0`)
if (migrateTo3) {
// Under -rewrite, patch `x _` to `(() => x)`
patch(Span(tree.span.start), "(() => ")
patch(Span(qual.span.end, tree.span.end), ")")
msg.actions
.flatMap(_.patches)
.map(actionPatch => patch(actionPatch.srcPos.span, actionPatch.replacement))
return typed(untpd.Function(Nil, qual), pt)
}
}
Expand Down Expand Up @@ -3951,10 +3951,17 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
def adaptNoArgsUnappliedMethod(wtp: MethodType, functionExpected: Boolean, arity: Int): Tree = {
/** Is reference to this symbol `f` automatically expanded to `f()`? */
def isAutoApplied(sym: Symbol): Boolean =
lazy val msg = MissingEmptyArgumentList(sym.show, tree)

sym.isConstructor
|| sym.matchNullaryLoosely
|| Feature.warnOnMigration(MissingEmptyArgumentList(sym.show, tree), tree.srcPos, version = `3.0`)
&& { patch(tree.span.endPos, "()"); true }
|| Feature.warnOnMigration(msg, tree.srcPos, version = `3.0`)
&& {
msg.actions
.flatMap(_.patches)
.map(actionPatch => patch(actionPatch.srcPos.span, actionPatch.replacement))
true
}

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

0 comments on commit e153597

Please sign in to comment.