Skip to content

Commit

Permalink
fixes and regression tests for viperproject#581
Browse files Browse the repository at this point in the history
  • Loading branch information
Pointerbender committed May 27, 2022
1 parent 5503e4a commit 87f22d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ case class PDestructorCall(name: String, rcv: PExp)
override def args: Seq[PExp] = Seq(rcv)

override def translateExp(t: Translator): Exp = {
val actualRcv = t.exp(rcv)
val so: Option[Map[TypeVar, Type]] = adtSubstitution match {
case Some(ps) => Some(ps.m.map(kv => TypeVar(kv._1) -> t.ttyp(kv._2)))
case None => None
Expand All @@ -472,6 +471,10 @@ case class PDestructorCall(name: String, rcv: PExp)
case Some(s) =>
val adt = t.getMembers()(this.adt.idndef.name).asInstanceOf[Adt]
assert(s.keys.toSet == adt.typVars.toSet)
val actualRcv = rcv match {
case pr@PResultLit() => Result(AdtType(adt, s))(t.liftPos(pr))
case _ => t.exp(rcv)
}
AdtDestructorApp(adt, name, actualRcv, s)(t.liftPos(this))
case _ => sys.error("type unification error - should report and not crash")
}
Expand All @@ -496,7 +499,6 @@ case class PDiscriminatorCall(name: PIdnUse, rcv: PExp)
override def args: Seq[PExp] = Seq(rcv)

override def translateExp(t: Translator): Exp = {
val actualRcv = t.exp(rcv)
val so: Option[Map[TypeVar, Type]] = adtSubstitution match {
case Some(ps) => Some(ps.m.map(kv => TypeVar(kv._1) -> t.ttyp(kv._2)))
case None => None
Expand All @@ -505,6 +507,10 @@ case class PDiscriminatorCall(name: PIdnUse, rcv: PExp)
case Some(s) =>
val adt = t.getMembers()(this.adt.idndef.name).asInstanceOf[Adt]
assert(s.keys.toSet == adt.typVars.toSet)
val actualRcv = rcv match {
case pr@PResultLit() => Result(AdtType(adt, s))(t.liftPos(pr))
case _ => t.exp(rcv)
}
AdtDiscriminatorApp(adt, name.name, actualRcv, s)(t.liftPos(this))
case _ => sys.error("type unification error - should report and not crash")
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/adt/issue-581.vpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
adt Test {
A()
B(b: Int)
}

function foo(): Test
ensures result.isA
{
A()
}

function bar(): Test
ensures result.isB
ensures result.b == 42
{
B(42)
}

0 comments on commit 87f22d1

Please sign in to comment.