]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Add glib.h include for TRUE/FALSE literal
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 2 Oct 2022 11:17:04 +0000 (13:17 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 2 Oct 2022 11:22:24 +0000 (13:22 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1364

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/basic-types/boolean-literal.c-expected [new file with mode: 0644]
tests/basic-types/boolean-literal.vala [new file with mode: 0644]
tests/parser/with-embedded.c-expected

index fb323e28e60865cf8b7abbb1cee7c232985dff6b..ccaf795478436da77cf295ef718e2314b96322aa 100644 (file)
@@ -6862,6 +6862,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
        public CCodeExpression get_boolean_cconstant (bool b) {
                if (context.profile == Profile.GOBJECT) {
+                       cfile.add_include ("glib.h");
                        return new CCodeConstant (b ? "TRUE" : "FALSE");
                } else {
                        cfile.add_include ("stdbool.h");
index dd6f39684da93f38ca7c58192ef5491098271223..6a2acf56c5ff5f9847b8b5bc5d799250c3c8a41c 100644 (file)
@@ -49,6 +49,7 @@ TESTS = \
        basic-types/floats.vala \
        basic-types/floats-boxed-cast.vala \
        basic-types/boolean.vala \
+       basic-types/boolean-literal.vala \
        basic-types/custom-types.vala \
        basic-types/default-gtype.vala \
        basic-types/strings.vala \
diff --git a/tests/basic-types/boolean-literal.c-expected b/tests/basic-types/boolean-literal.c-expected
new file mode 100644 (file)
index 0000000..89441a6
--- /dev/null
@@ -0,0 +1,23 @@
+/* basic_types_boolean_literal.c generated by valac, the Vala compiler
+ * generated from basic_types_boolean_literal.vala, do not modify */
+
+#include <glib.h>
+
+static void _vala_main (void);
+
+static void
+_vala_main (void)
+{
+       if (TRUE) {
+               return;
+       }
+}
+
+int
+main (int argc,
+      char ** argv)
+{
+       _vala_main ();
+       return 0;
+}
+
diff --git a/tests/basic-types/boolean-literal.vala b/tests/basic-types/boolean-literal.vala
new file mode 100644 (file)
index 0000000..be7d379
--- /dev/null
@@ -0,0 +1,5 @@
+void main () {
+       if (true) {
+               return;
+       }
+}
index d825c379fb84c6b417663c396a83887c2d196c37..29935c99e6b593a49b4eba64fb16ae89bb0832ba 100644 (file)
@@ -1,9 +1,9 @@
 /* parser_with_embedded.c generated by valac, the Vala compiler
  * generated from parser_with_embedded.vala, do not modify */
 
+#include <glib.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib.h>
 
 #define _g_free0(var) (var = (g_free (var), NULL))
 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);