digital-asset / daml

The Daml smart contract language
https://www.digitalasset.com/developers
Other
802 stars 204 forks source link

replace .toIfc() and .unsafeFromIfc(...) with singletons and overloads #13919

Closed S11001001 closed 2 years ago

S11001001 commented 2 years ago

Design from https://github.com/digital-asset/daml/issues/13668#issuecomment-1106899636 . For this part:

stefanobaghino-da commented 2 years ago

Since we are renaming and we can still break: prepending unsafe to a method that could throw is not a common pattern in Java. I propose to:

S11001001 commented 2 years ago

@stefanobaghino-da unsafeFromInterface does not exist in cases where a template doesn't implement an interface, so there is never cause to throw such an exception. This is "unsafe" because we are coercing from interface-contract-ID to template-contract-ID, which we cannot check locally.

stefanobaghino-da commented 2 years ago

@stefanobaghino-da unsafeFromInterface does not exist in cases where a template doesn't implement an interface, so there is never cause to throw such an exception. This is "unsafe" because we are coercing from interface-contract-ID to template-contract-ID, which we cannot check locally.

Does that throw an exception? Under what circumstances?

S11001001 commented 2 years ago

Does that throw an exception? Under what circumstances?

No, it doesn't.

Foo.ContractId z = // ...
var bcid = Bar.ContractId.unsafeFromInterface(
    z.toInterface(some.SharedIface.INTERFACE));
bcid.exerciseSomeBarChoice(...); // submitting this exercise will fail
stefanobaghino-da commented 2 years ago

I see, thanks!