fix parsing of functions with incorrect type indexes

This commit is contained in:
Ilya Rezvov
2018-04-13 16:56:25 -07:00
parent 16bbc3d198
commit 23ed83a42e
4 changed files with 24 additions and 17 deletions
+4 -6
View File
@@ -1528,12 +1528,9 @@ desugarize fields =
getTypeIndex defs (IndexedTypeUse (Named ident) Nothing) =
fromIntegral <$> findIndex (\(TypeDef i _) -> i == Just ident) defs
getTypeIndex defs (IndexedTypeUse (Index n) (Just funcType)) = do
guard $ length defs > fromIntegral n
guard $ matchTypeFunc funcType $ defs !! fromIntegral n
return n
getTypeIndex defs (IndexedTypeUse (Index n) Nothing) = do
guard $ length defs > fromIntegral n
return n
getTypeIndex defs (IndexedTypeUse (Index n) Nothing) = return n
-- imports
synImportToStruct :: [TypeDef] -> Import -> S.Import
@@ -1649,8 +1646,9 @@ desugarize fields =
IndexedTypeUse _ (Just FuncType { params }) -> params
AnonimousTypeUse FuncType { params } -> params
_ ->
let TypeDef _ FuncType { params } = types mod !! fromIntegral typeIdx in
params
if fromIntegral typeIdx < length (types mod)
then let TypeDef _ FuncType { params } = types mod !! fromIntegral typeIdx in params
else []
in
let ctx = FunCtx mod [] locals params in
S.Function {