Open akrmn opened 1 year ago
Similarly,
queryContractId : (Template t, IsParties p, HasCallStack) => p -> ContractId t -> Script (Optional t)
can be used with t ~ <some interface>
, crashing at runtime; and query : (Template t, IsParties p) => p -> Script [(ContractId t, t)]
can be used with t ~ <some interface>
, returning the empty list (regardless of the existence of contracts with the requested interface on the ledger)We should constrain the type to be templates only, possibly by restricting it to HasAgreement as a short term solution. Long term (or short term if feasible), we want a nicer solution to restrict it to templates in a way that's not dependent on HasAgreement.
the difficulty here is in naming; we could well add a compiler typeclass e.g. IsTemplate t
but we already have a type class synonym Template t
•, and it would be hard to explain to users when to use one or the other.
If we had another term for the existing Template t
type class synonym, e.g. LedgerType t
, we could then define Template t
(and Interface t
while we're at it) as an empty class with LedgerType t
as superclass, with the compiler generating the appropriate instances while forbidding manually-written ones. Functions that only work with templates (resp. interfaces) would have the constraint Template t =>
(resp. Interface t =>
), while functions that work with either would have LedgerType t =>
.
type LedgerType t =
( HasTemplateTypeRep t
, HasToAnyTemplate t
, HasFromAnyTemplate t
)
class LedgerType t => Template t
class LedgerType t => Interface t
However, I'm not satisfied with the name LedgerType
and, with backwards compatibility in mind, this would have to be a multi-step process to first deprecate the existing Template
type class synonym and later introduce the new definitions.
In SDK 2.4.2,
createCmd : Template t => t -> Commands (ContractId t)
only accepts templates because the definition of classTemplate
before #15347 requiredHasAgreement
, which interfaces do not have. After #15347, the definition ofTemplate
has been relaxed, so nowTemplate x
also holds for any interfacex
, so now the type checker allows usingcreateCmd
with an interface value as argument. However, this now crashes the scenario service with "SValue.toValue: unexpected SAny"To reproduce
daml
fromhead
withdaml-sdk-head
daml test
from that directoryExpectation
Reality
Files