Skip to content

[backport] Refutable extractor may be an Apply tree #15672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,13 @@ trait Checking {
case RefutableExtractor =>
val extractor =
val UnApply(fn, _, _) = pat: @unchecked
fn match
tpd.funPart(fn) match
case Select(id, _) => id
case TypeApply(Select(id, _), _) => id
em"pattern binding uses refutable extractor `$extractor`"
case _ => EmptyTree
if extractor.isEmpty then
em"pattern binding uses refutable extractor"
else
em"pattern binding uses refutable extractor `$extractor`"

val fix =
if isPatDef then "adding `: @unchecked` after the expression"
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i15650.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Rational

import scala.quoted.*

class TC

object meta:
object rationalTE:
def unapply(using Quotes)(tr: quotes.reflect.TypeRepr): Option[Rational] = ???

object rationalTC:
def unapply(using Quotes)(using TC)(tr: quotes.reflect.TypeRepr): Option[Rational] = ???

def foo(using Quotes)(p: quotes.reflect.TypeRepr): Unit =
val rationalTE(e) = p // warn: pattern binding uses refutable extractor `meta.rationalTE`

def bar(using Quotes)(using TC)(p: quotes.reflect.TypeRepr): Unit =
val rationalTC(c) = p // warn: pattern binding uses refutable extractor `meta.rationalTC`