Skip to content

Commit e2024da

Browse files
committed
Ensure pt span exists in implicitParams migration
Fixes #23022
1 parent 372f889 commit e2024da

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ trait Migrations:
131131
/** Report implicit parameter lists and rewrite implicit parameter list to contextual params */
132132
def implicitParams(tree: Tree, tp: MethodOrPoly, pt: FunProto)(using Context): Unit =
133133
val mversion = mv.ImplicitParamsWithoutUsing
134-
if tp.companion == ImplicitMethodType && pt.applyKind != ApplyKind.Using && pt.args.nonEmpty then
134+
if tp.companion == ImplicitMethodType && pt.applyKind != ApplyKind.Using && pt.args.nonEmpty && pt.args.head.span.exists then
135135
// The application can only be rewritten if it uses parentheses syntax.
136136
// See issue #22927 and related tests.
137137
val hasParentheses = checkParentheses(tree, pt)
@@ -160,8 +160,10 @@ trait Migrations:
160160
end implicitParams
161161

162162
private def checkParentheses(tree: Tree, pt: FunProto)(using Context): Boolean =
163-
ctx.source.content
164-
.slice(tree.span.end, pt.args.head.span.start)
163+
val ptSpan = pt.args.head.span
164+
ptSpan.exists
165+
&& ctx.source.content
166+
.slice(tree.span.end, ptSpan.start)
165167
.exists(_ == '(')
166168

167169
private def patchImplicitParams(tree: Tree, pt: FunProto)(using Context): Unit =

tests/pos/i23022.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait ExtractorWithImplicit:
2+
3+
object Yikes:
4+
def unapply(implicit M: String): Option[Any] = ???
5+
6+
def expand: Any =
7+
given String = "Hey"
8+
"Wut" match
9+
case Yikes(_) => ???
10+
case _ => ???
11+
12+

0 commit comments

Comments
 (0)