From da382440d4f201ac9f2754420541e4b3ae6699de Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Jan 2021 15:56:37 +0100 Subject: [PATCH] Do not warn on canceled splices in quoted patterns The following is a valid and minimal quoted patten: `case '{ $x } =>` Fixes #9804 --- compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala | 2 +- tests/pos-special/fatal-warnings/i9804.scala | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/pos-special/fatal-warnings/i9804.scala diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index b0c5a4bf0698..3478b493caeb 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -43,7 +43,7 @@ trait QuotesAndSplices { def typedQuote(tree: untpd.Quote, pt: Type)(using Context): Tree = { record("typedQuote") tree.quoted match { - case untpd.Splice(innerExpr) if tree.isTerm => + case untpd.Splice(innerExpr) if tree.isTerm && !ctx.mode.is(Mode.Pattern) => report.warning("Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ.", tree.srcPos) case untpd.TypSplice(innerType) if tree.isType => report.warning("Canceled splice directly inside a quote. '[ ${ XYZ } ] is equivalent to XYZ.", tree.srcPos) diff --git a/tests/pos-special/fatal-warnings/i9804.scala b/tests/pos-special/fatal-warnings/i9804.scala new file mode 100644 index 000000000000..8aa4c34eca31 --- /dev/null +++ b/tests/pos-special/fatal-warnings/i9804.scala @@ -0,0 +1,5 @@ +import scala.quoted._ + +def f[A: Type](e: Expr[A])(using Quotes): Expr[A] = e match { + case '{ $e2 } => e2 +}