Skip to content

Commit

Permalink
fix: bug with implicit returns in TVoid function and test compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
oriollinan committed Jan 12, 2025
1 parent 5cce6fb commit 48c1e8f
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 198 deletions.
1 change: 0 additions & 1 deletion glados.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ test-suite glados-test
Ast.Parser.TypeDefinitionSpec
Ast.Parser.TypeSpec
Ast.Parser.ExprSpec
Ast.ParserSpec
Codegen.CodegenSpec

hs-source-dirs: test
Expand Down
7 changes: 5 additions & 2 deletions lib/Ast/Parser/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ parseFunction = do
name <- PU.identifier
ft <- PU.symbol ":" *> PT.parseType
case ft of
(AT.TFunction {AT.paramTypes = pts}) -> do
(AT.TFunction ret pts _) -> do
params <- PU.symbol "=" *> M.many (PU.lexeme PU.identifier)
mapM_ (\(p, t) -> S.modify (PS.insertVar p t)) $ zip params pts
S.modify (PS.insertVar name ft)
block <- parseBlock
let body = implicitReturn block
let body =
if ret /= AT.TVoid
then implicitReturn block
else block
return $ AT.Function {AT.funcLoc = srcLoc, AT.funcName = name, AT.funcType = ft, AT.funcParams = params, AT.funcBody = body}
_ -> M.customFailure $ AU.InvalidFunctionType name ft

Expand Down
Loading

0 comments on commit 48c1e8f

Please # to comment.