Skip to content

Ensure pt span exists in implicitParams migration #23372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Migrations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ trait Migrations:
/** Report implicit parameter lists and rewrite implicit parameter list to contextual params */
def implicitParams(tree: Tree, tp: MethodOrPoly, pt: FunProto)(using Context): Unit =
val mversion = mv.ImplicitParamsWithoutUsing
if tp.companion == ImplicitMethodType && pt.applyKind != ApplyKind.Using && pt.args.nonEmpty then
if tp.companion == ImplicitMethodType && pt.applyKind != ApplyKind.Using && pt.args.nonEmpty && pt.args.head.span.exists then
// The application can only be rewritten if it uses parentheses syntax.
// See issue #22927 and related tests.
val hasParentheses = checkParentheses(tree, pt)
Expand Down Expand Up @@ -160,8 +160,10 @@ trait Migrations:
end implicitParams

private def checkParentheses(tree: Tree, pt: FunProto)(using Context): Boolean =
ctx.source.content
.slice(tree.span.end, pt.args.head.span.start)
val ptSpan = pt.args.head.span
ptSpan.exists
&& ctx.source.content
.slice(tree.span.end, ptSpan.start)
.exists(_ == '(')

private def patchImplicitParams(tree: Tree, pt: FunProto)(using Context): Unit =
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i23022.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
trait ExtractorWithImplicit:

object Yikes:
def unapply(implicit M: String): Option[Any] = ???

def expand: Any =
given String = "Hey"
"Wut" match
case Yikes(_) => ???
case _ => ???


Loading