Skip to content

Commit c471fcc

Browse files
authored
fix: don't emit Unit type the casts (#1349)
Previously, the forms cast to the type Unit would still result in variable assignment emissions, which produces invalid C. Consider the case: ```clojure ;; type of System.exit is (Int -> a) (defn main [] (the () (System.exit 0))) ``` This previously produced bad variable assignments. It now works as expected and emits only the function call.
1 parent 0682f1a commit c471fcc

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Emit.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
530530
var <- visit indent value
531531
let Just t = ty
532532
fresh = mangle (freshVar info)
533-
appendToSrc (addIndent indent ++ tyToCLambdaFix t ++ " " ++ fresh ++ " = " ++ var ++ "; // From the 'the' function.\n")
533+
unless (isUnit t)
534+
(appendToSrc (addIndent indent ++ tyToCLambdaFix t ++ " " ++ fresh ++ " = " ++ var ++ "; // From the 'the' function.\n"))
534535
pure fresh
535536
-- Ref
536537
[XObj Ref _ _, value] ->

0 commit comments

Comments
 (0)