Skip to content

Commit

Permalink
Report an error instead of panicing when mixing nested modules with p…
Browse files Browse the repository at this point in the history
…aram modules
  • Loading branch information
yav committed Mar 12, 2021
1 parent 522328b commit e0cef62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Cryptol/TypeCheck/CheckModuleInstance.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# Language OverloadedStrings #-}
module Cryptol.TypeCheck.CheckModuleInstance (checkModuleInstance) where

import Data.Map ( Map )
Expand All @@ -22,8 +23,9 @@ checkModuleInstance :: Module {- ^ type-checked functor -} ->
InferM Module -- ^ Instantiated module
checkModuleInstance func inst
| not (null (mSubModules func) && null (mSubModules inst)) =
panic "checkModuleInstance"
[ "XXX: Nested modules and functors do not work yet." ]
do recordError $ TemporaryError
"Cannot combine nested modules with old-style parameterized modules"
pure func -- doesn't matter?
| otherwise =
do tMap <- checkTyParams func inst
vMap <- checkValParams func tMap inst
Expand Down
18 changes: 15 additions & 3 deletions src/Cryptol/TypeCheck/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ data Error = KindMismatch (Maybe TypeSource) Kind Kind
| TypeShadowing String Name String
| MissingModTParam (Located Ident)
| MissingModVParam (Located Ident)

| TemporaryError Doc
-- ^ This is for errors that don't fit other cateogories.
-- We should not use it much, and is generally to be used
-- for transient errors, which are due to incomplete
-- implementation.
deriving (Show, Generic, NFData)

-- | When we have multiple errors on the same location, we show only the
Expand All @@ -147,6 +153,10 @@ errorImportance :: Error -> Int
errorImportance err =
case err of
BareTypeApp -> 11 -- basically a parse error
TemporaryError {} -> 11
-- show these as usually means the user used something that doesn't work


KindMismatch {} -> 10
TyVarWithParams {} -> 9
TypeMismatch {} -> 8
Expand Down Expand Up @@ -236,6 +246,8 @@ instance TVars Error where
MissingModTParam {} -> err
MissingModVParam {} -> err

TemporaryError {} -> err


instance FVS Error where
fvs err =
Expand Down Expand Up @@ -269,6 +281,8 @@ instance FVS Error where
MissingModTParam {} -> Set.empty
MissingModVParam {} -> Set.empty

TemporaryError {} -> Set.empty

instance PP Warning where
ppPrec = ppWithNamesPrec IntMap.empty

Expand Down Expand Up @@ -436,9 +450,7 @@ instance PP (WithNames Error) where
MissingModVParam x ->
"Missing definition for value parameter" <+> quotes (pp (thing x))




TemporaryError doc -> doc
where
bullets xs = vcat [ "" <+> d | d <- xs ]

Expand Down

0 comments on commit e0cef62

Please sign in to comment.