Skip to content

Commit 0f1bd60

Browse files
committed
Refutable extractor may be an Apply tree
And in fact we need to be able to handle arbitrary parameter lists (and type parameter lists) when extracting the extractor name. Fixes scala#15650
1 parent 1d45f5d commit 0f1bd60

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,13 @@ trait Checking {
816816
case RefutableExtractor =>
817817
val extractor =
818818
val UnApply(fn, _, _) = pat: @unchecked
819-
fn match
819+
tpd.funPart(fn) match
820820
case Select(id, _) => id
821-
case TypeApply(Select(id, _), _) => id
822-
em"pattern binding uses refutable extractor `$extractor`"
821+
case _ => EmptyTree
822+
if extractor.isEmpty then
823+
em"pattern binding uses refutable extractor"
824+
else
825+
em"pattern binding uses refutable extractor `$extractor`"
823826

824827
val fix =
825828
if isPatDef then "adding `: @unchecked` after the expression"

tests/pos/i15650.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Rational
2+
3+
import scala.quoted.*
4+
5+
class TC
6+
7+
object meta:
8+
object rationalTE:
9+
def unapply(using Quotes)(tr: quotes.reflect.TypeRepr): Option[Rational] = ???
10+
11+
object rationalTC:
12+
def unapply(using Quotes)(using TC)(tr: quotes.reflect.TypeRepr): Option[Rational] = ???
13+
14+
def foo(using Quotes)(p: quotes.reflect.TypeRepr): Unit =
15+
val rationalTE(e) = p // warn: pattern binding uses refutable extractor `meta.rationalTE`
16+
17+
def bar(using Quotes)(using TC)(p: quotes.reflect.TypeRepr): Unit =
18+
val rationalTC(c) = p // warn: pattern binding uses refutable extractor `meta.rationalTC`

0 commit comments

Comments
 (0)