Skip to content

Commit af16d56

Browse files
authored
Merge pull request #15651 from griggt/fix-15650
Refutable extractor may be an Apply tree
2 parents 7e20b81 + d1e8de0 commit af16d56

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

+6-3
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

+18
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)