Skip to content

Commit 7bae575

Browse files
committed
Check level in pattern match
1 parent 3cef701 commit 7bae575

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ class Typer extends Namer
19371937
case quoted if quoted.isType =>
19381938
typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext).withSpan(tree.span)
19391939
case quoted =>
1940-
if (ctx.mode.is(Mode.Pattern)) {
1940+
if (ctx.mode.is(Mode.Pattern) && level == 0) {
19411941
val exprPt = pt.baseType(defn.QuotedExprClass)
19421942
val quotedPt = if (exprPt.exists) exprPt.argTypesHi.head else defn.AnyType
19431943
val quoted1 = typedExpr(quoted, quotedPt)(quoteContext.addMode(Mode.QuotedPattern))
@@ -1989,7 +1989,7 @@ class Typer extends Namer
19891989
ctx.warning("Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ.", tree.sourcePos)
19901990
typed(innerExpr, pt)
19911991
case expr =>
1992-
if (ctx.mode.is(Mode.QuotedPattern)) {
1992+
if (ctx.mode.is(Mode.QuotedPattern) && level == 1) {
19931993
fullyDefinedType(pt, "quoted pattern selector", tree.span)
19941994
val pat = typedPattern(expr, defn.QuotedExprType.appliedTo(pt))(
19951995
spliceContext.retractMode(Mode.QuotedPattern))

tests/neg/quotedPatterns.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
3+
val x = '{1 + 2}
4+
5+
def f(x: Int) = x
6+
def g(x: Int, y: Int) = x * y
7+
8+
x match {
9+
case '{ val a = '{ println($y) }; 0 } => ??? // error: Not found: y
10+
case _ =>
11+
}
12+
}

0 commit comments

Comments
 (0)