Skip to content

Commit

Permalink
Fixes #620 (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArquintL authored Feb 26, 2025
1 parent 91344bb commit d2bc4f8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class DefaultPrettyPrinter extends PrettyPrinter with kiama.output.PrettyPrinter
case PureLet(left, right, exp) =>
"let" <+> showVar(left) <+> "==" <+> parens(showExpr(right)) <+> "in" <+> showExpr(exp)

case Old(op, _) => "old" <> parens(showExpr(op))
case Old(op) => "old" <> parens(showExpr(op))

case LabeledOld(label, operand) => "old" <> brackets(showProxy(label)) <> parens(showExpr(operand))

Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/viper/gobra/ast/internal/Program.scala
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,12 @@ case class PureLet(left: LocalVar, right: Expr, in: Expr)(val info: Source.Parse

case class Let(left: LocalVar, right: Expr, in: Assertion)(val info: Source.Parser.Info) extends Assertion

case class Old(operand: Expr, typ: Type)(val info: Source.Parser.Info) extends Expr
case class Old(operand: Expr)(val info: Source.Parser.Info) extends Expr {
override def typ: Type = operand.typ.withAddressability(Addressability.rValue)
}

case class LabeledOld(label: LabelProxy, operand: Expr)(val info: Source.Parser.Info) extends Expr {
override val typ: Type = operand.typ
override val typ: Type = operand.typ.withAddressability(Addressability.rValue)
}

case class Conditional(cond: Expr, thn: Expr, els: Expr, typ: Type)(val info: Source.Parser.Info) extends Expr
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/viper/gobra/frontend/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4291,7 +4291,7 @@ object Desugar extends LazyLogging {
val typ = typeD(info.typ(expr), info.addressability(expr))(src)

expr match {
case POld(op) => for {o <- go(op)} yield in.Old(o, typ)(src)
case POld(op) => for {o <- go(op)} yield in.Old(o)(src)
case PLabeledOld(l, op) => for {o <- go(op)} yield in.LabeledOld(labelProxy(l), o)(src)
case PBefore(op) => for {o <- go(op)} yield in.LabeledOld(in.LabelProxy("before")(src), o)(src)
case PConditional(cond, thn, els) => for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AssertionEncoding extends Encoding {
import viper.gobra.translator.util.ViperWriter.CodeLevel._

override def expression(ctx: Context): in.Expr ==> CodeWriter[vpr.Exp] = {
case n@ in.Old(op, _) => for { o <- ctx.expression(op)} yield withSrc(vpr.Old(o), n)
case n@ in.Old(op) => for { o <- ctx.expression(op)} yield withSrc(vpr.Old(o), n)
case n@ in.LabeledOld(l, op) => for {o <- ctx.expression(op)} yield withSrc(vpr.LabelledOld(o, l.name), n)

case n@ in.Negation(op) => for{o <- ctx.expression(op)} yield withSrc(vpr.Not(o), n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class BuiltInEncoding extends Encoding {
i => in.ExprAssertion(
in.GhostEqCmp(
in.IndexedExp(resultParam, i, sliceType)(src),
in.Old(in.IndexedExp(sliceParam, i, sliceType)(src), elemType)(src)
in.Old(in.IndexedExp(sliceParam, i, sliceType)(src))(src)
)(src)
)(src)
}
Expand Down Expand Up @@ -586,7 +586,7 @@ class BuiltInEncoding extends Encoding {
in.ExprAssertion(
in.GhostEqCmp(
in.IndexedExp(dstParam, i, dstUnderlyingType)(src),
in.Old(in.IndexedExp(srcParam, i, srcUnderlyingType)(src), srcUnderlyingType.elems)(src)
in.Old(in.IndexedExp(srcParam, i, srcUnderlyingType)(src))(src)
)(src)
)(src)
}
Expand All @@ -598,7 +598,7 @@ class BuiltInEncoding extends Encoding {
in.ExprAssertion(
in.GhostEqCmp(
in.IndexedExp(dstParam, i, dstUnderlyingType)(src),
in.Old(in.IndexedExp(dstParam, i, dstUnderlyingType)(src), dstUnderlyingType.elems)(src)
in.Old(in.IndexedExp(dstParam, i, dstUnderlyingType)(src))(src)
)(src)
)(src)
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/resources/regressions/issues/000620-1.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package main

type MyType struct {
x int
}

func main() {
mySlice := make([]MyType, 0)
snd := []MyType{MyType{1}}
mySlice = append(perm(1/2), mySlice, snd...)
}
14 changes: 14 additions & 0 deletions src/test/resources/regressions/issues/000620-2.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package main

type MyStruct struct {
x int
}

func test() {
myStruct @ := MyStruct{42}
l:
assert myStruct == old[l](myStruct)
}
10 changes: 10 additions & 0 deletions src/test/resources/regressions/issues/000620-3.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package main

func test() {
myInt @ := 42
l:
assert myInt == old[l](myInt)
}

0 comments on commit d2bc4f8

Please sign in to comment.