From 74d7d5767b42d55d91f16e8f113dcedb74eb3235 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Sat, 4 Sep 2021 14:29:44 +0200 Subject: [PATCH] fix: elide void definitions (#1305) --- src/Emit.hs | 6 ++++-- test/regression.carp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Emit.hs b/src/Emit.hs index 3a19d1d8..e003e15a 100644 --- a/src/Emit.hs +++ b/src/Emit.hs @@ -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 -> diff --git a/test/regression.carp b/test/regression.carp index e9c69b50..4eb728a2 100644 --- a/test/regression.carp +++ b/test/regression.carp @@ -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")