Add serializability check for exceptions. (#8151)

* Add serializability check for exceptions.

Part of #8020

changelog_begin
changelog_end

* typo
This commit is contained in:
Sofia Faro 2020-12-07 14:44:24 +00:00 committed by GitHub
parent ab43da3f7a
commit 84e5881236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -46,6 +46,7 @@ data SerializabilityRequirement
| SRChoiceRes
| SRKey
| SRDataType
| SRExceptionArg
-- | Reason why a type is not serializable.
data UnserializabilityReason
@ -170,6 +171,7 @@ instance Pretty SerializabilityRequirement where
SRChoiceRes -> "choice result"
SRDataType -> "serializable data type"
SRKey -> "template key"
SRExceptionArg -> "exception argument"
instance Pretty UnserializabilityReason where
pPrint = \case

View File

@ -163,6 +163,12 @@ checkTemplate mod0 tpl = do
for_ (tplKey tpl) $ \key -> withContext (ContextTemplate mod0 tpl TPKey) $ do
checkType SRKey (tplKeyType key)
-- | Check whether exception is serializable.
checkException :: MonadGamma m => Module -> DefException -> m ()
checkException mod0 exn = do
let tcon = Qualified PRSelf (moduleName mod0) (exnName exn)
checkType SRExceptionArg (TCon tcon)
-- | Check whether a module satisfies all serializability constraints.
checkModule :: MonadGamma m => Module -> m ()
checkModule mod0 = do
@ -172,3 +178,6 @@ checkModule mod0 = do
for_ (moduleTemplates mod0) $ \tpl ->
withContext (ContextTemplate mod0 tpl TPWhole) $
checkTemplate mod0 tpl
for_ (moduleExceptions mod0) $ \exn ->
withContext (ContextDefException mod0 exn) $
checkException mod0 exn