Skip to content

Commit

Permalink
Add missing serializability checks for interfaces (#12483)
Browse files Browse the repository at this point in the history
* Add missing serializability checks for interfaces

The checks for argument & result type were missing before. I openey
#12482 to do the same fix
on the Scala side.

fixes #12475 

changelog_begin
changelog_end

* .

changelog_begin
changelog_end
  • Loading branch information
cocreature authored Jan 19, 2022
1 parent 7c59728 commit 681f8fc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ checkTemplate mod0 tpl = do
for_ (tplKey tpl) $ \key -> withContext (ContextTemplate mod0 tpl TPKey) $ do
checkType SRKey (tplKeyType key)

-- | Check whether a template satisfies all serializability constraints.
checkInterface :: MonadGamma m => Module -> DefInterface -> m ()
checkInterface _mod0 iface = do
-- TODO https://github.com/digital-asset/daml/issues/12051
-- Add per interface choice context.
for_ (intFixedChoices iface) $ \ch -> do
checkType SRChoiceArg (snd (chcArgBinder ch))
checkType SRChoiceRes (chcReturnType ch)

-- | Check whether exception is serializable.
checkException :: MonadGamma m => Module -> DefException -> m ()
checkException mod0 exn = do
Expand All @@ -179,3 +188,6 @@ checkModule mod0 = do
for_ (moduleExceptions mod0) $ \exn ->
withContext (ContextDefException mod0 exn) $
checkException mod0 exn
for_ (moduleInterfaces mod0) $ \iface ->
withContext (ContextDefInterface mod0 iface) $
checkInterface mod0 iface
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- @SINCE-LF-FEATURE DAML_INTERFACE
-- @ERROR expected serializable type
module InterfaceSerializabilityArgument where

data NonSerializable = NonSerializable (() -> ())

-- Dummy Eq and Show instances so we blow up in the serializability checker rather than
-- the GHC typechecker.

instance Eq NonSerializable where
(==) = error "undefined"
instance Show NonSerializable where
show = error "undefined"

interface I where
p : Party

choice NonSerializableArgument : ()
with f : NonSerializable
controller p this
do pure ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- @SINCE-LF-FEATURE DAML_INTERFACE
-- @ERROR expected serializable type
module InterfaceSerializabilityResult where

data NonSerializable = NonSerializable (() -> ())

-- Dummy Eq and Show instances so we blow up in the serializability checker rather than
-- the GHC typechecker.

instance Eq NonSerializable where
(==) = error "undefined"
instance Show NonSerializable where
show = error "undefined"

interface I where
p : Party

choice NonSerializableResult : NonSerializable
controller p this
do pure (NonSerializable identity)

0 comments on commit 681f8fc

Please sign in to comment.