From e2024da10ac5d0213710d97c21a4cbf24bd69da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Bra=C4=8Devac?= Date: Sun, 15 Jun 2025 23:55:53 +0200 Subject: [PATCH] Ensure pt span exists in implicitParams migration Fixes #23022 --- compiler/src/dotty/tools/dotc/typer/Migrations.scala | 8 +++++--- tests/pos/i23022.scala | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i23022.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Migrations.scala b/compiler/src/dotty/tools/dotc/typer/Migrations.scala index 328e66e7cd80..d811987383c6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Migrations.scala +++ b/compiler/src/dotty/tools/dotc/typer/Migrations.scala @@ -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) @@ -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 = diff --git a/tests/pos/i23022.scala b/tests/pos/i23022.scala new file mode 100644 index 000000000000..0d88674b7f8d --- /dev/null +++ b/tests/pos/i23022.scala @@ -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 _ => ??? + +