Skip to content

Improve error message for refutable quoted patterns #16669

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
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
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ trait Checking {
case _ => EmptyTree
if extractor.isEmpty then
em"pattern binding uses refutable extractor"
else if extractor.symbol eq defn.QuoteMatching_ExprMatch then
em"pattern binding uses refutable extractor `'{...}`"
else if extractor.symbol eq defn.QuoteMatching_TypeMatch then
em"pattern binding uses refutable extractor `'[...]`"
else
em"pattern binding uses refutable extractor `$extractor`"

Expand Down
8 changes: 8 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i16649-refutable.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Error: tests/neg-custom-args/fatal-warnings/i16649-refutable.scala:4:6 ----------------------------------------------
4 | val '{ ($y: Int) + ($z: Int) } = x // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| pattern binding uses refutable extractor `'{...}`
|
| If this usage is intentional, this can be communicated by adding `: @unchecked` after the expression,
| which may result in a MatchError at runtime.
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
4 changes: 4 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i16649-refutable.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import quoted.*

def foo(using Quotes)(x: Expr[Int]) =
val '{ ($y: Int) + ($z: Int) } = x // error