Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/Pact/Typechecker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -839,20 +839,22 @@ withScopeBodyToFun fnname modname funTy body deftype info = do
return $ FDefun info modname fnname deftype funType args tcs funId

assocStepYieldReturns :: TopLevel Node -> [AST Node] -> TC ()
assocStepYieldReturns (TopFun (FDefun _ _ _ Defpact _ _ _ _) _) steps =
assocStepYieldReturns (TopFun (FDefun _ _ _ Defpact _ _ _ rty) _) steps =
void $ toStepYRs >>= foldM go (Nothing,0::Int)
where
lastStep = pred $ length steps
toStepYRs = forM steps $ \step -> case step of
Step{..} -> case (_aYieldResume, _aRollback) of

-- check that a cross-chain yield and rollback do not occur
-- in the same step, otherwise build the tuple
(Just y, Just{}) ->
if _yrCrossChain y
then die'' step "Illegal rollback with yield"
else return (_aNode, _aYieldResume)
_ -> return (_aNode, _aYieldResume)
Step{..} -> do
-- Associate the DefPact return type with each step
assocNode rty _aNode
case (_aYieldResume, _aRollback) of
-- check that a cross-chain yield and rollback do not occur
-- in the same step, otherwise build the tuple
(Just y, Just{}) ->
if _yrCrossChain y
then die'' step "Illegal rollback with yield"
else return (_aNode, _aYieldResume)
_ -> return (_aNode, _aYieldResume)
_ -> die'' step "Non-step in defpact"
yrMay l yr = preview (_Just . l . _Just) yr
go :: (Maybe (YieldResume Node),Int) -> (Node, Maybe (YieldResume Node)) -> TC (Maybe (YieldResume Node),Int)
Expand All @@ -879,7 +881,6 @@ assocStepYieldReturns (TopFun (FDefun _ _ _ Defpact _ _ _ _) _) steps =
b' <- lookupSchemaTy b
debug $ "assocYRSchemas: " ++ showPretty ((a,a'),(b,b'))
assocParams (_aId a) a' b'

assocStepYieldReturns _ _ = return ()


Expand Down
4 changes: 2 additions & 2 deletions tests/pact/caps.repl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

(defpact test-pact-guards (id:string)
(step (step1 id))
(step (step2 (read-msg "id"))))
(step (let ((s2 (step2 (read-msg "id")))) "step2")))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this binding do, and how is it extending the test? Is this suggesting that the return type of test-pact-guards should be :string?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step has return type string, with this change, we enforce that all steps have the same return type. Hence, the change will return the "step2" string. This is a fix to a pre-existing test (on caps).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add some comments to the test describing what's going on here and what exactly is being tested by these odd constructions? (Namely, binding to a name that is never used). Everything else looks good!


(defun step1 (id:string)
(insert guard-table id { "g": (create-pact-guard "test")}))
Expand Down Expand Up @@ -207,7 +207,7 @@

(env-data { "id": "a"})

(expect "pact enforce succeeds" 1 (at 'result (continue-pact 1 false (hash "pact-guards-a-id"))))
(expect "pact enforce succeeds" "step2" (continue-pact 1 false (hash "pact-guards-a-id")))

(pact-state true)
(env-hash (hash "pact-guards-b-id"))
Expand Down
10 changes: 10 additions & 0 deletions tests/pact/tc.repl
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@
"test anon lambdas"
(map (lambda (i) (> i 1)) [1 2 3]))

(defpact fail-steps-type-missmatch: integer ()
Comment thread
rsoeldner marked this conversation as resolved.
"test type missmatch of steps"
(step "missmatch")
(step 1))

(defpact tc-steps-type-pass: integer ()
"test type match of steps"
(step 1)
(step 1))

)

(create-table persons)
Expand Down