Skip to content

Commit 769cf87

Browse files
authored
Improve error message for refutable quoted patterns (#16669)
As noted in #16649 (comment)
2 parents dbb1e6c + d8b98a0 commit 769cf87

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,10 @@ trait Checking {
846846
case _ => EmptyTree
847847
if extractor.isEmpty then
848848
em"pattern binding uses refutable extractor"
849+
else if extractor.symbol eq defn.QuoteMatching_ExprMatch then
850+
em"pattern binding uses refutable extractor `'{...}`"
851+
else if extractor.symbol eq defn.QuoteMatching_TypeMatch then
852+
em"pattern binding uses refutable extractor `'[...]`"
849853
else
850854
em"pattern binding uses refutable extractor `$extractor`"
851855

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg-custom-args/fatal-warnings/i16649-refutable.scala:4:6 ----------------------------------------------
2+
4 | val '{ ($y: Int) + ($z: Int) } = x // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| pattern binding uses refutable extractor `'{...}`
5+
|
6+
| If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
7+
| which may result in a MatchError at runtime.
8+
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import quoted.*
2+
3+
def foo(using Quotes)(x: Expr[Int]) =
4+
val '{ ($y: Int) + ($z: Int) } = x // error

0 commit comments

Comments
 (0)