Couldn't match type ‘Update’ with ‘(->) c0’

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.

made some further updates but still having some issues on creating the right scenario for the
UpdateRegistration choice from my DAML

   nonconsuming UpdateRegistration : ContractId CitizenRegistration
         with
           newCitizenDetails : CitizenInfo
        do
         (oldRegistrationCid, oldRegistrationData) <- fetchByKey @CitizenRegistration (key this)
         archive oldRegistrationCid
         create CitizenRegistration with 
           registrationCid = oldRegistrationCid  
           registrationData = newCitizenDetails

Here is my scenario

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

   let alicekey = CitizenKey with citizen = alice ; id = "1"
  (oldRegistrationCid, oldRegistrationData) <- fetchByKey @CitizenRegistration (alicekey)

  let citizenkey = key oldRegistrationData
  let newCitizenDetails = CitizenInfo with citizendetail1 = "UpdatedText1" ; citizendetail2 ="UpdatedText2" ; citizendetail3 = "UpdatedText3" 

  aliceupdate <- submit alice do
    exercise UpdateRegistration with
      registrationCid = key oldRegistrationData ; registrationData = newCitizenDetails

    return (aliceregistration,bobregistration, aliceupdate)

Getting some errors on this last part

C:\Users\bartc\Documents\Github\DAML-Covid19\daml\Registration.daml:70:18: error:
    • Couldn't match type ‘Update’ with ‘(->) c0’
        arising from a functional dependency between:
          constraint ‘HasSubmit Scenario ((->) c0)’
            arising from a use of ‘submit’
          instance ‘HasSubmit Scenario Update’ at <no location info>
    • In a stmt of a 'do' block:
        aliceupdate <- submit
                         alice
                         do exercise
                              UpdateRegistration
                                {registrationCid = citizenkey,
                                 registrationData = newCitizenDetails}
      In the first argument of ‘scenario’, namely
        ‘do alice <- getParty "Alice"
            bob <- getParty "Bob"
            let citizenkey = ...
            let citizeninfo = ...
            ....’
      In the expression:
        scenario
          do alice <- getParty "Alice"
             bob <- getParty "Bob"
             let citizenkey = ...
             let citizeninfo = ...
             ....typecheck
Peek Problem (Alt+F8)
No quick fixes available


C:\Users\bartc\Documents\Github\DAML-Covid19\daml\Registration.daml:65:48: error:
    • Couldn't match type ‘Update’ with ‘Scenario’
      Expected type: Scenario
                       (ContractId CitizenRegistration, CitizenRegistration)
        Actual type: Update
                       (ContractId CitizenRegistration, CitizenRegistration)
    • In a stmt of a 'do' block:
        (oldRegistrationCid, oldRegistrationData) <- fetchByKey
                                                       @CitizenRegistration (alicekey)
      In the first argument of ‘scenario’, namely
        ‘do alice <- getParty "Alice"
            bob <- getParty "Bob"
            let citizenkey = ...
            let citizeninfo = ...
            ....’
      In the expression:
        scenario
          do alice <- getParty "Alice"
             bob <- getParty "Bob"
             let citizenkey = ...
             let citizeninfo = ...
             ....typecheck
Peek Problem (Alt+F8)
No quick fixes available
1 Like

It looks like you’re missing a submit around the fetchByKey. This would turn the Update into a Scenario, at least addressing the second error. The first error may be cascading from that. Let us know if that helps.

1 Like

It also seems that your last return statement is indented by 4 spaces, but should be two. That could be causing the other error.

1 Like

This fixed one problem

I changed it to

(oldRegistrationCid, oldRegistrationData) <- submit alice do fetchByKey @CitizenRegistration (alicekey)

Other error messages remain

Error 1

C:\Users\bartc\Documents\Github\DAML-Covid19\daml\Registration.daml:70:18: error:
    • Couldn't match type ‘Update’ with ‘(->) c0’
        arising from a functional dependency between:
          constraint ‘HasSubmit Scenario ((->) c0)’
            arising from a use of ‘submit’
          instance ‘HasSubmit Scenario Update’ at <no location info>
    • In a stmt of a 'do' block:
        aliceupdate <- submit
                         alice
                         do exercise
                              UpdateRegistration
                                {registrationCid = citizenkey,
                                 registrationData = newCitizenDetails}
      In the first argument of ‘scenario’, namely
        ‘do alice <- getParty "Alice"
            bob <- getParty "Bob"
            let citizenkey = ...
            let citizeninfo = ...
            ....’
      In the expression:
        scenario
          do alice <- getParty "Alice"
             bob <- getParty "Bob"
             let citizenkey = ...
             let citizeninfo = ...
             ....typecheck

Error 2

C:\Users\bartc\Documents\Github\DAML-Covid19\daml\Registration.daml:71:14: error:
    • Constructor ‘UpdateRegistration’ does not have field ‘registrationCid’
    • In the first argument of ‘exercise’, namely
        ‘UpdateRegistration
           {registrationCid = citizenkey,
            registrationData = newCitizenDetails}’
      In a stmt of a 'do' block:
        exercise
          UpdateRegistration
            {registrationCid = citizenkey,
             registrationData = newCitizenDetails}
      In the second argument of ‘submit’, namely
        ‘do exercise
              UpdateRegistration
                {registrationCid = citizenkey,
                 registrationData = newCitizenDetails}’typecheck

Error 3

C:\Users\bartc\Documents\Github\DAML-Covid19\daml\Registration.daml:71:14: error:
    • Constructor ‘UpdateRegistration’ does not have field ‘registrationData’
    • In the first argument of ‘exercise’, namely
        ‘UpdateRegistration
           {registrationCid = citizenkey,
            registrationData = newCitizenDetails}’
      In a stmt of a 'do' block:
        exercise
          UpdateRegistration
            {registrationCid = citizenkey,
             registrationData = newCitizenDetails}
      In the second argument of ‘submit’, namely
        ‘do exercise
              UpdateRegistration
                {registrationCid = citizenkey,
                 registrationData = newCitizenDetails}’typecheck

Error 4

C:\Users\bartc\Documents\Github\DAML-Covid19\daml\Registration.daml:71:14: error:
    • Constructor ‘UpdateRegistration’ does not have the required strict field(s): newCitizenDetails
    • In the first argument of ‘exercise’, namely
        ‘UpdateRegistration
           {registrationCid = citizenkey,
            registrationData = newCitizenDetails}’
      In a stmt of a 'do' block:
        exercise
          UpdateRegistration
            {registrationCid = citizenkey,
             registrationData = newCitizenDetails}
      In the second argument of ‘submit’, namely
        ‘do exercise
              UpdateRegistration
                {registrationCid = citizenkey,
                 registrationData = newCitizenDetails}’typecheck

Error 5

C:\Users\bartc\Documents\Github\DAML-Covid19\daml\Registration.daml:71:14: error:
    • Couldn't match expected type ‘ContractId t0’
                  with actual type ‘UpdateRegistration’
    • In the first argument of ‘exercise’, namely
        ‘UpdateRegistration
           {registrationCid = citizenkey,
            registrationData = newCitizenDetails}’
      In a stmt of a 'do' block:
        exercise
          UpdateRegistration
            {registrationCid = citizenkey,
             registrationData = newCitizenDetails}
      In the second argument of ‘submit’, namely
        ‘do exercise
              UpdateRegistration
                {registrationCid = citizenkey,
                 registrationData = newCitizenDetails}’typecheck
1 Like

@bartcant hope it might help you.

module Test where

data CitizenKey = CitizenKey with
    citizen : Party 
    id: Text
      deriving(Eq,Show)

data CitizenInfo =CitizenInfo with
    citizendetail1 : Text 
    citizendetail2 : Text 
    citizendetail3 : Text 
      deriving(Eq,Show)


template CitizenRegistration
  with
   registrationCid : CitizenKey
   registrationData : CitizenInfo
  where
    signatory registrationCid.citizen

    key (registrationCid,registrationData):(CitizenKey,CitizenInfo) 
    maintainer key._1.citizen
    
    nonconsuming choice UpdateRegistration : ContractId CitizenRegistration
      with
           newCitizenDetails : CitizenInfo

      controller  registrationCid.citizen
        do
         (oldRegistrationCid, oldRegistrationData) <- fetchByKey @CitizenRegistration (key this)
         archive oldRegistrationCid
         create CitizenRegistration with 
           registrationCid = oldRegistrationData.registrationCid 
           registrationData = newCitizenDetails



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

  let 
    alicekey = CitizenKey with citizen = alice ; id = "1"
    alicedata = CitizenInfo with  citizendetail1 = "Text1" ; citizendetail2 ="Text2" ; citizendetail3 = "Text3"
  (oldRegistrationCid, oldRegistrationData) <- submit alice do fetchByKey @CitizenRegistration (alicekey,alicedata)

  let citizenkey = key oldRegistrationData
  let newCitizenDetails = CitizenInfo with citizendetail1 = "UpdatedText1" ; citizendetail2 ="UpdatedText2" ; citizendetail3 = "UpdatedText3" 

  aliceupdate <- submit alice do
    exercise aliceregistration UpdateRegistration with newCitizenDetails = newCitizenDetails

  return (aliceregistration,bobregistration, aliceupdate)
1 Like