Last statement in a do block must be an expression?
- bartcantOP 1
Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.
I am hitting a snag in the scenario. I hope you can help pinpoint the problem
example = scenario do alice <- getParty "Alice" bob <- getParty "Bob" let citizenkey = CitizenKey with citizen = alice ; id = "1" let citizeninfo = CitizenInfo with citizendetail1 = "Text1" ; citizendetail2 ="Text2" ; citizendetail3 = "Text3" submit alice do create CitizenRegistration with registrationCid = citizenkey; registrationData = citizeninfo let citizenkey = CitizenKey with citizen = bob ; id = "2" let citizeninfo = CitizenInfo with citizendetail1 = "Text1" ; citizendetail2 ="Text2" ; citizendetail3 = "Text3" bobregistration <- submit bob do create CitizenRegistration with registrationCid = citizenkey; registrationData = citizeninfoI trying to understand the correct format for
bobregistration <- submit bob do create CitizenRegistration with registrationCid = citizenkey; registrationData = citizeninfoIt gives me the following error
error: The last statement in a 'do' block must be an expression bobregistration <- submit bob do create CitizenRegistration {registrationCid = citizenkey, registrationData = citizeninfo}typecheck - jamesljaworski85 3
Hey @bartcant. It looks to me like you need a return statement at the end of your scenario. Without a return statement, you won’t be able to return the result for both Alice and Bob’s registration.
example = scenario do alice <- getParty "Alice" bob <- getParty "Bob" let citizenkey = CitizenKey with citizen = alice ; id = "1" let citizeninfo = CitizenInfo with citizendetail1 = "Text1" ; citizendetail2 ="Text2" ; citizendetail3 = "Text3" aliceRegistration <- submit alice do create CitizenRegistration with registrationCid = citizenkey; registrationData = citizeninfo let citizenkey = CitizenKey with citizen = bob ; id = "2" let citizeninfo = CitizenInfo with citizendetail1 = "Text1" ; citizendetail2 ="Text2" ; citizendetail3 = "Text3" bobRegistration <- submit bob do create CitizenRegistration with registrationCid = citizenkey; registrationData = citizeninfo return(aliceRegistration, bobRegistration) - rohanjr 1
That’s right. It looks like formatting of the
doin
bartcant:bobregistration <- submit bob dois fine but the compiler is complaining about the top level scenario:
bartcant:example = scenario doAs @jamesljaworski85 pointed out, the last statement of a
docan’t be a<-(orlet) binding. However it could be something other thanreturnif it has the right type, e.g. acreate.