From 0f1bd60c79d48b94058e4c72ef71ab91b9808f9e Mon Sep 17 00:00:00 2001 From: Tom Grigg Date: Mon, 11 Jul 2022 16:59:50 -0700 Subject: [PATCH] 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 --- .../src/dotty/tools/dotc/typer/Checking.scala | 9 ++++++--- tests/pos/i15650.scala | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i15650.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 313d238181e1..d5da280e78f2 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -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" diff --git a/tests/pos/i15650.scala b/tests/pos/i15650.scala new file mode 100644 index 000000000000..3e335756f43a --- /dev/null +++ b/tests/pos/i15650.scala @@ -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`