Skip to content

Commit 74d7d57

Browse files
authored
fix: elide void definitions (#1305)
1 parent ae2186f commit 74d7d57

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Emit.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
307307
appendToSrc (addIndent indent ++ "{\n")
308308
let innerIndent = indent + indentAmount
309309
ret <- visit innerIndent expr
310-
appendToSrc (addIndent innerIndent ++ pathToC path ++ " = " ++ ret ++ ";\n")
310+
when (ret /= "") $ appendToSrc (addIndent innerIndent ++ pathToC path ++ " = " ++ ret ++ ";\n")
311311
delete innerIndent info
312312
appendToSrc (addIndent indent ++ "}\n")
313313
pure ""
@@ -895,7 +895,9 @@ toDeclaration (Binder meta xobj@(XObj (Lst xobjs) _ ty)) =
895895
in defnToDeclaration meta path argList retTy ++ ";\n"
896896
[XObj Def _ _, XObj (Sym path _) _ _, _] ->
897897
let Just t = ty
898-
in "" ++ tyToCLambdaFix t ++ " " ++ pathToC path ++ ";\n"
898+
in if (isUnit t)
899+
then ""
900+
else tyToCLambdaFix t ++ " " ++ pathToC path ++ ";\n"
899901
XObj (Deftype t) _ _ : XObj (Sym path _) _ _ : rest ->
900902
defStructToDeclaration t path rest
901903
XObj (DefSumtype t) _ _ : XObj (Sym _ _) _ _ : rest ->

test/regression.carp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
(load "Test.carp")
33
(load "Vector.carp")
44

5+
; void definitions should get elided (issue #1296)
6+
(def is-void ())
7+
58
; this is a test-only module to test module resolution (see #288)
69
(defmodule Foo
710
(register init (Fn [] Int) "fooInit")

0 commit comments

Comments
 (0)