Skip to content

Commit

Permalink
Fixed scoping of let in PureMethodsToFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMensing committed Nov 28, 2024
1 parent f7b0f0c commit ce2783c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/rewrite/vct/rewrite/PureMethodsToFunctions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ case class PureMethodsToFunctions[Pre <: Generation]() extends Rewriter[Pre] {

val currentAbstractMethod: ScopedStack[AbstractMethod[Pre]] = ScopedStack()

private val variableMap: SuccessionMap[Variable[Pre], Variable[Post]] =
SuccessionMap()

def countAssignments(v: Variable[Pre], s: Statement[Pre]): Option[Int] =
s match {
case Return(_) => Some(0)
Expand Down Expand Up @@ -98,18 +95,22 @@ case class PureMethodsToFunctions[Pre <: Generation]() extends Rewriter[Pre] {
}
toExpression(impl, alt)
case Assign(Local(ref), e) =>
alt match {
case Some(exprAlt) =>
val vDecl = variableMap.getOrElseUpdate(
ref.decl,
variables.collect { dispatch(ref.decl) }._1.head,
)
Some(Let[Post](vDecl, dispatch(e), exprAlt))
case None =>
throw MethodCannotIntoFunction(
currentAbstractMethod.top,
"Pure method cannot end with assign statement",
)
localHeapVariables.scope {
variables.scope {
alt match {
case Some(exprAlt) =>
Some(Let[Post](
variables.collect { dispatch(ref.decl) }._1.head,
dispatch(e),
exprAlt,
))
case None =>
throw MethodCannotIntoFunction(
currentAbstractMethod.top,
"Pure method cannot end with assign statement",
)
}
}
}

case _ => None
Expand Down

0 comments on commit ce2783c

Please sign in to comment.