Skip to content

Commit 5540f13

Browse files
committed
merge fixes: extract typedCase to be reused in TreeChecker.
1 parent 9d1b4bf commit 5540f13

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

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

+17-16
Original file line numberDiff line numberDiff line change
@@ -618,24 +618,25 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
618618
accu(Set.empty, selType)
619619
}
620620

621-
def typedCase(tree: untpd.CaseDef): CaseDef = track("typedCase") {
622-
def caseRest(pat: Tree)(implicit ctx: Context) = {
623-
gadtSyms foreach (_.resetGADTFlexType)
624-
pat foreachSubTree {
625-
case b: Bind =>
626-
if (ctx.scope.lookup(b.name) == NoSymbol) ctx.enter(b.symbol)
627-
else ctx.error(d"duplicate pattern variable: ${b.name}", b.pos)
628-
case _ =>
629-
}
630-
val guard1 = typedExpr(tree.guard, defn.BooleanType)
631-
val body1 = typedExpr(tree.body, pt)
632-
assignType(cpy.CaseDef(tree)(pat, guard1, body1), body1)
621+
cases mapconserve (typedCase(_, pt, selType, gadtSyms))
622+
}
623+
624+
def typedCase(tree: untpd.CaseDef, pt: Type, selType: Type, gadtSyms: Set[Symbol])(implicit ctx: Context): CaseDef = track("typedCase") {
625+
def caseRest(pat: Tree)(implicit ctx: Context) = {
626+
gadtSyms foreach (_.resetGADTFlexType)
627+
pat foreachSubTree {
628+
case b: Bind =>
629+
if (ctx.scope.lookup(b.name) == NoSymbol) ctx.enter(b.symbol)
630+
else ctx.error(d"duplicate pattern variable: ${b.name}", b.pos)
631+
case _ =>
633632
}
634-
val doCase: () => CaseDef =
635-
() => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.setNewScope)
636-
(doCase /: gadtSyms)((op, tsym) => tsym.withGADTFlexType(op))()
633+
val guard1 = typedExpr(tree.guard, defn.BooleanType)
634+
val body1 = typedExpr(tree.body, pt)
635+
assignType(cpy.CaseDef(tree)(pat, guard1, body1), body1)
637636
}
638-
cases mapconserve typedCase
637+
val doCase: () => CaseDef =
638+
() => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.setNewScope)
639+
(doCase /: gadtSyms)((op, tsym) => tsym.withGADTFlexType(op))()
639640
}
640641

641642
def typedReturn(tree: untpd.Return)(implicit ctx: Context): Return = track("typedReturn") {

0 commit comments

Comments
 (0)