Skip to content
CCPEDIAby Unity Nodes
App Development

Last statement in a do block must be an expression?

3 posts2,546 views5 likesLast activity Jun 2020

  1. 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 = citizeninfo
    

    I trying to understand the correct format for

         bobregistration <- submit bob do 
        create CitizenRegistration with 
          registrationCid = citizenkey; registrationData = citizeninfo
    

    It 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
    
  2. 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)
  3. rohanjr 1

    That’s right. It looks like formatting of the do in

    bartcant:

    bobregistration <- submit bob do

    is fine but the compiler is complaining about the top level scenario:

    bartcant:

    example = scenario do

    As @jamesljaworski85 pointed out, the last statement of a do can’t be a <- (or let) binding. However it could be something other than return if it has the right type, e.g. a create.