diff --git a/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Serializability.hs b/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Serializability.hs index ec8b79a59b3a..6a976b0f03a1 100644 --- a/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Serializability.hs +++ b/compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Serializability.hs @@ -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 @@ -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 diff --git a/compiler/damlc/tests/daml-test-files/InterfaceSerializabilityArgument.daml b/compiler/damlc/tests/daml-test-files/InterfaceSerializabilityArgument.daml new file mode 100644 index 000000000000..3321f2b093e3 --- /dev/null +++ b/compiler/damlc/tests/daml-test-files/InterfaceSerializabilityArgument.daml @@ -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 () diff --git a/compiler/damlc/tests/daml-test-files/InterfaceSerializabilityResult.daml b/compiler/damlc/tests/daml-test-files/InterfaceSerializabilityResult.daml new file mode 100644 index 000000000000..7e7750f0ea16 --- /dev/null +++ b/compiler/damlc/tests/daml-test-files/InterfaceSerializabilityResult.daml @@ -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)