Skip to content

Commit d1e8de0

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 #15650
1 parent 7e20b81 commit d1e8de0

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
@@ -830,10 +830,13 @@ trait Checking {
830830
case RefutableExtractor =>
831831
val extractor =
832832
val UnApply(fn, _, _) = pat: @unchecked
833-
fn match
833+
tpd.funPart(fn) match
834834
case Select(id, _) => id
835-
case TypeApply(Select(id, _), _) => id
836-
em"pattern binding uses refutable extractor `$extractor`"
835+
case _ => EmptyTree
836+
if extractor.isEmpty then
837+
em"pattern binding uses refutable extractor"
838+
else
839+
em"pattern binding uses refutable extractor `$extractor`"
837840

838841
val fix =
839842
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)