Skip to content

Commit 7baf519

Browse files
committed
Enter pattern-bound variables into scope when checking guard
1 parent 0ec589c commit 7baf519

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
730730
val scrutineeBinding = normalizeBinding(ValDef(scrutineeSym, scrutinee))
731731

732732
def reduceCase(cdef: untpd.CaseDef): MatchRedux = {
733-
def guardOK = cdef.guard.isEmpty || {
734-
typer.typed(cdef.guard, defn.BooleanType) match {
733+
val caseBindingsBuf = new mutable.ListBuffer[MemberDef]()
734+
def guardOK(implicit ctx: Context) = cdef.guard.isEmpty || {
735+
val guardCtx = ctx.fresh.setNewScope
736+
caseBindingsBuf.foreach(binding => guardCtx.enter(binding.symbol))
737+
typer.typed(cdef.guard, defn.BooleanType)(guardCtx) match {
735738
case ConstantValue(true) => true
736739
case _ => false
737740
}
738741
}
739-
val caseBindingsBuf = new mutable.ListBuffer[MemberDef]()
740742
if (scrutType != defn.ImplicitScrutineeTypeRef) caseBindingsBuf += scrutineeBinding
741743
val gadtCtx = typer.gadtContext(gadtSyms).addMode(Mode.GADTflexible)
742744
val pat1 = typer.typedPattern(cdef.pat, scrutType)(gadtCtx)

0 commit comments

Comments
 (0)