Skip to content

Commit

Permalink
correct object evaluation order, closes #260
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Oct 15, 2024
1 parent 69e9b20 commit 83cc02c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pact-tests/Pact/Core/Test/PactContinuationTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ testManagedCaps = do
let allCmds = [sysModuleCmd,acctModuleCmd,createAcctCmd,managedPay,managedPayFails]
allResults <- runAll allCmds

mhash <- mkModuleHash "PkJ6B966fhCGDEWeTfbfP78btLEfM9SpjButLlA4Lj4"
mhash <- mkModuleHash "xkYy5KYtEkV1WFZ791iCnZjRBx6um5FEe1aU-rPCOv8"

runResults allResults $ do
sysModuleCmd `succeedsWith` (`shouldBe` textVal "system module loaded")
Expand Down
29 changes: 29 additions & 0 deletions pact-tests/pact-tests/object-evaluation-order-regression.repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
;; Regression for https://github.com/kadena-io/pact-5/issues/260

(module my-mod G
@doc "A simple module that manages a counter"
(defcap G() true)

(defschema counter-schema
cnt:integer)

(deftable counter-table:{counter-schema})

(defun init:string ()
@doc "Initialize the counter"
(insert counter-table "SINGLETON" {'cnt:0})
)

(defun increment:integer ()
@doc "Increment the counter and return the old value"
(with-read counter-table "SINGLETON" {'cnt:=old-value}
(update counter-table "SINGLETON" {'cnt:(+ 1 old-value)})
old-value)
)

)
; Init the counter
(create-table counter-table)
(my-mod.init)

(expect "check evaluation order from left to right" {'a:(my-mod.increment), 'b:(my-mod.increment), 'c:(my-mod.increment)} {'a: 0, 'b:1, 'c:2})
2 changes: 1 addition & 1 deletion pact/Pact/Core/Syntax/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ Object :: { ParsedExpr }
: '{' ObjectBody '}' { Object $2 (combineSpan (_ptInfo $1) (_ptInfo $3)) }

ObjectBody :: { [(Field, ParsedExpr)] }
: FieldPairs { $1 }
: FieldPairs { reverse $1 }

FieldPair :: { (Field, ParsedExpr) }
: STR ':' Expr { (Field (getStr $1), $3) }
Expand Down

0 comments on commit 83cc02c

Please sign in to comment.