fix: elide void definitions (#1305)

This commit is contained in:
Veit Heller 2021-09-04 14:29:44 +02:00 committed by GitHub
parent ae2186f4b7
commit 74d7d5767b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -307,7 +307,7 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
appendToSrc (addIndent indent ++ "{\n")
let innerIndent = indent + indentAmount
ret <- visit innerIndent expr
appendToSrc (addIndent innerIndent ++ pathToC path ++ " = " ++ ret ++ ";\n")
when (ret /= "") $ appendToSrc (addIndent innerIndent ++ pathToC path ++ " = " ++ ret ++ ";\n")
delete innerIndent info
appendToSrc (addIndent indent ++ "}\n")
pure ""
@ -895,7 +895,9 @@ toDeclaration (Binder meta xobj@(XObj (Lst xobjs) _ ty)) =
in defnToDeclaration meta path argList retTy ++ ";\n"
[XObj Def _ _, XObj (Sym path _) _ _, _] ->
let Just t = ty
in "" ++ tyToCLambdaFix t ++ " " ++ pathToC path ++ ";\n"
in if (isUnit t)
then ""
else tyToCLambdaFix t ++ " " ++ pathToC path ++ ";\n"
XObj (Deftype t) _ _ : XObj (Sym path _) _ _ : rest ->
defStructToDeclaration t path rest
XObj (DefSumtype t) _ _ : XObj (Sym _ _) _ _ : rest ->

View File

@ -2,6 +2,9 @@
(load "Test.carp")
(load "Vector.carp")
; void definitions should get elided (issue #1296)
(def is-void ())
; this is a test-only module to test module resolution (see #288)
(defmodule Foo
(register init (Fn [] Int) "fooInit")