diff --git a/compiler/damlc/daml-stdlib-src/DA/Internal/Desugar.daml b/compiler/damlc/daml-stdlib-src/DA/Internal/Desugar.daml index 3caa9a950568..047418f638fa 100644 --- a/compiler/damlc/daml-stdlib-src/DA/Internal/Desugar.daml +++ b/compiler/damlc/daml-stdlib-src/DA/Internal/Desugar.daml @@ -16,6 +16,7 @@ module DA.Internal.Desugar ( Party, ContractId, Update, Any, NonConsuming(..), PreConsuming(..), PostConsuming(..), Consuming(..), Implements(..), + TypeRep, ) where import DA.Internal.Prelude diff --git a/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml b/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml index c862d0379c9c..4fe6fb183861 100644 --- a/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml +++ b/compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml @@ -10,6 +10,7 @@ module InterfaceDesugared where import DA.Assert ((===)) +import DA.Action (unless) data Split = Split { splitAmount : Int } @@ -28,6 +29,7 @@ class fromToken : Token -> Optional t toTokenContractId : ContractId t -> ContractId Token fromTokenContractId : ContractId Token -> Update (Optional (ContractId t)) + tokenTypeRep : t -> DA.Internal.Desugar.TypeRep getOwner : t -> Party getAmount : t -> Int setAmount : t -> Int -> Token @@ -56,6 +58,7 @@ instance IsToken Token where fromToken = GHC.Types.primitive @"EFromInterface" toTokenContractId = GHC.Types.primitive @"EToInterfaceContractId" fromTokenContractId = GHC.Types.primitive @"UFromInterfaceContractId" + tokenTypeRep = GHC.Types.primitive @"$TO_TYPE_REP" getOwner = GHC.Types.primitiveInterface @"getOwner" getAmount = GHC.Types.primitiveInterface @"getAmount" setAmount = GHC.Types.primitiveInterface @"setAmount" @@ -114,6 +117,7 @@ instance IsToken Asset where fromToken = GHC.Types.primitive @"EFromInterface" toTokenContractId = GHC.Types.primitive @"EToInterfaceContractId" fromTokenContractId = GHC.Types.primitive @"UFromInterfaceContractId" + tokenTypeRep = GHC.Types.primitive @"$TO_TYPE_REP" getOwner Asset{..} = owner getAmount Asset{..} = amount setAmount this x = toToken (this with amount = x) @@ -242,5 +246,6 @@ main = scenario do None -> abort "expected Asset" Some Asset {amount} -> amount === 25 + unless (tokenTypeRep token3 == tokenTypeRep token4) $ error "Type representations are different." pure () diff --git a/compiler/damlc/tests/daml-test-files/InterfaceExperimental.daml b/compiler/damlc/tests/daml-test-files/InterfaceExperimental.daml index 19f2f6c7eafb..37a892315ff2 100644 --- a/compiler/damlc/tests/daml-test-files/InterfaceExperimental.daml +++ b/compiler/damlc/tests/daml-test-files/InterfaceExperimental.daml @@ -69,6 +69,30 @@ template NotAsset where signatory p + implements Token where + let getAmount = error "getAmount" + + choice Split : (ContractId Token, ContractId Token) + with + splitAmount : Int + controller p + do + error "Split" + + choice Transfer : ContractId Token + with + newOwner : Party + controller p + do + error "Transfer" + + nonconsuming choice Noop : () + with + nothing : () + controller p + do + error "Noop" + main = scenario do alice <- getParty "Alice" bob <- getParty "Bob" @@ -79,6 +103,6 @@ main = scenario do interfaceCreate token interfaceSignatory token === [alice] interfaceObserver token === [bob, alice] - unless (toTypeRep token == toTypeRep asset) $ abort "TypeReps are not equal" - unless (toTypeRep token /= toTypeRep notAsset) $ abort "TypeReps are equal" + unless (tokenTypeRep token == tokenTypeRep asset) $ abort "TypeReps are not equal" + unless (tokenTypeRep token /= tokenTypeRep notAsset) $ abort "TypeReps are equal" pure ()