Skip to content

Commit b61181f

Browse files
committed
Do not remove InPatternAlternative when typing subexpressions
We use typedExpr to type the contents of a quoted pattern. In that case it must not have the Pattern mode mut should keep the InPatternAlternative because it will be needed in the pattern located in the splices.
1 parent 9ed7ac5 commit b61181f

File tree

3 files changed

+2
-15
lines changed

3 files changed

+2
-15
lines changed

compiler/src/dotty/tools/dotc/core/Mode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object Mode {
8989
/** Don't suppress exceptions thrown during show */
9090
val PrintShowExceptions: Mode = newMode(18, "PrintShowExceptions")
9191

92-
val PatternOrTypeBits: Mode = Pattern | Type | InPatternAlternative
92+
val PatternOrTypeBits: Mode = Pattern | Type
9393

9494
/** We are elaborating the fully qualified name of a package clause.
9595
* In this case, identifiers should never be imported.

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,6 @@ trait QuotesAndSplices {
243243
res
244244
}
245245

246-
def checkAlternativeBinds(pat0: Tree): Unit =
247-
def rec(pat: Tree): Unit =
248-
pat match
249-
case Typed(pat, _) => rec(pat)
250-
case UnApply(_, _, pats) => pats.foreach(rec)
251-
case pat: Bind =>
252-
report.error(IllegalVariableInPatternAlternative(pat.symbol.name), pat.withSpan(pat.nameSpan))
253-
rec(pat.body)
254-
case _ =>
255-
if ctx.mode.is(Mode.InPatternAlternative) then rec(pat0)
256-
257246
val patBuf = new mutable.ListBuffer[Tree]
258247
val freshTypePatBuf = new mutable.ListBuffer[Tree]
259248
val freshTypeBindingsBuff = new mutable.ListBuffer[Tree]
@@ -265,7 +254,6 @@ trait QuotesAndSplices {
265254
val newSplice = ref(defn.QuotedRuntime_exprSplice).appliedToType(tpt1.tpe).appliedTo(Typed(pat, exprTpt))
266255
transform(newSplice)
267256
case Apply(TypeApply(fn, targs), Apply(sp, pat :: Nil) :: args :: Nil) if fn.symbol == defn.QuotedRuntimePatterns_patternHigherOrderHole =>
268-
checkAlternativeBinds(pat)
269257
args match // TODO support these patterns. Possibly using scala.quoted.util.Var
270258
case SeqLiteral(args, _) =>
271259
for arg <- args; if arg.symbol.is(Mutable) do
@@ -278,7 +266,6 @@ trait QuotesAndSplices {
278266
patBuf += pat1
279267
}
280268
case Apply(fn, pat :: Nil) if fn.symbol.isExprSplice =>
281-
checkAlternativeBinds(pat)
282269
try ref(defn.QuotedRuntimePatterns_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
283270
finally {
284271
val patType = pat.tpe.widen

tests/neg-macros/i14696.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def test(a: Expr[Any])(using Quotes): Unit = a match
55
case '{ $x1: String } | '{ ${_}: Int } => // error
66
case '{ $x: String } | '{ $x: Int } => // error // error
77
case '{ $x1: String } | '{ ${x2: Expr[Int]} } => // error // error
8-
case '{ ${Str(x)}: String } | '{ ${y @ Str(z)}: Int } => // error // error // error
8+
case '{ ${Str(x)}: String } | '{ ${y @ Str(z)}: Int } => // error // error
99
case '{ val x: Int = ???; ${_}(x): String } | '{ '{ val x: String = ???; ${_}(x): String }} =>
1010
case '{ val x: Int = ???; $f(x): String } | '{ val x: String = ???; ${_}(x): String } => // error
1111
case '{ val x: Int = ???; $f(x): String } | '{ val x: String = ???; $f(x): String } => // error // error

0 commit comments

Comments
 (0)