1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Throw and catch export errors

This commit is contained in:
joshvera 2018-04-17 19:12:53 -04:00
parent 6e4aeeaaac
commit 249e2977ab
3 changed files with 11 additions and 5 deletions

View File

@ -29,6 +29,7 @@ instance ( Effectful m
analyzeTerm eval term = resumeException @(EvalError value) (liftAnalyze analyzeTerm eval term) (
\yield err -> case err of
DefaultExportError{} -> yield ()
ExportError{} -> yield ()
IntegerFormatError{} -> yield 0
FloatFormatError{} -> yield 0
RationalFormatError{} -> yield 0

View File

@ -93,6 +93,7 @@ data EvalError value resume where
FloatFormatError :: ByteString -> EvalError value Scientific
RationalFormatError :: ByteString -> EvalError value Rational
DefaultExportError :: EvalError value ()
ExportError :: ModulePath -> Name -> EvalError value ()
-- | Look up and dereference the given 'Name', throwing an exception for free variables.
@ -104,10 +105,14 @@ deriving instance Show (EvalError a b)
instance Show1 (EvalError value) where
liftShowsPrec _ _ = showsPrec
instance Eq1 (EvalError term) where
liftEq _ (FreeVariableError a) (FreeVariableError b) = a == b
liftEq _ (FreeVariablesError a) (FreeVariablesError b) = a == b
liftEq _ DefaultExportError DefaultExportError = True
liftEq _ _ _ = False
liftEq _ (FreeVariableError a) (FreeVariableError b) = a == b
liftEq _ (FreeVariablesError a) (FreeVariablesError b) = a == b
liftEq _ DefaultExportError DefaultExportError = True
liftEq _ (ExportError a b) (ExportError c d) = (a == c) && (b == d)
liftEq _ (IntegerFormatError a) (IntegerFormatError b) = a == b
liftEq _ (FloatFormatError a) (FloatFormatError b) = a == b
liftEq _ (RationalFormatError a) (RationalFormatError b) = a == b
liftEq _ _ _ = False
throwValueError :: MonadEvaluatable location term value m => ValueError location value resume -> m resume

View File

@ -189,7 +189,7 @@ instance Evaluatable QualifiedExportFrom where
-- Look up addresses in importedEnv and insert the aliases with addresses into the exports.
for_ exportSymbols $ \(name, alias) -> do
let address = Env.lookup name importedEnv
maybe (cannotExport modulePath name) (addExport name alias . Just) address
maybe (throwEvalError $ ExportError modulePath name) (addExport name alias . Just) address
unit
where
cannotExport moduleName name = fail $