Skip to content

Commit e36f426

Browse files
committed
Avoid duplication of scrutinee in lowered matches (from #860)
1 parent 2c77b59 commit e36f426

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

core/src/main/scala/stainless/ast/SymbolOps.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ trait SymbolOps extends inox.ast.SymbolOps { self: TypeOps =>
144144

145145
def rewritePM(e: Expr): Option[Expr] = e match {
146146
case m @ MatchExpr(scrut, cases) =>
147+
val scrutVd = ValDef.fresh("scrut", scrut.getType).setPos(m)
148+
val scrutV = scrutVd.toVariable
147149
val condsAndRhs = for (cse <- cases) yield {
148-
val map = mapForPattern(scrut, cse.pattern)
149-
val patCond = conditionForPattern[Path](scrut, cse.pattern, includeBinders = false)
150+
val map = mapForPattern(scrutV, cse.pattern)
151+
val patCond = conditionForPattern[Path](scrutV, cse.pattern, includeBinders = false)
150152
val realCond = cse.optGuard match {
151153
case Some(g) => patCond withCond replaceFromSymbols(map, g)
152154
case None => patCond
@@ -170,7 +172,7 @@ trait SymbolOps extends inox.ast.SymbolOps { self: TypeOps =>
170172
}
171173
})
172174

173-
Some(bigIte)
175+
Some(Let(scrutVd, scrut, bigIte).copiedFrom(m))
174176

175177
case _ => None
176178
}

0 commit comments

Comments
 (0)