The following piece of code fails to typecheck with the following message:
• Couldn't match type ‘B’ with ‘A’
Expected type: Update (ContractId A)
Actual type: Update (ContractId B)
• In the expression: create (B s)
In a stmt of a 'do' block:
_ <- if flag then create (A s) else create (B s)
In the expression:
do if flag then create (A s) else create (B s)
return ()typecheck
template A
with
s: Party
where
signatory s
template B
with
s: Party
where
signatory s
template Helper
with
s: Party
where
signatory s
nonconsuming choice DoIt: ()
with
flag: Bool
controller s
do
if flag then
create (A s)
else
create (B s)
return ()
I do not care about return values of neither create A
and create B
.
What’d be a clean way to make this code compile?
My current workaround is:
template Helper
with
s: Party
where
signatory s
nonconsuming choice DoIt: ()
with
flag: Bool
controller s
do
if flag then
(create (A s), return ())._2
else
(create (B s), return ())._2
return ()