]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Include "glib-object.h" for typeof expression
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 1 Mar 2019 08:45:56 +0000 (09:45 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 1 Mar 2019 08:45:56 +0000 (09:45 +0100)
codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/enums/default-gtype.vala [new file with mode: 0644]
tests/errors/default-gtype.vala [new file with mode: 0644]
tests/structs/default-gtype.vala [new file with mode: 0644]

index b7d0de0100c19aca2c73b0ec6b70986744009573..acbb763ce459dafeb7b9b4171a613d305170409c 100644 (file)
@@ -5192,6 +5192,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        }
 
        public override void visit_typeof_expression (TypeofExpression expr) {
+               cfile.add_include ("glib-object.h");
+
                set_cvalue (expr, get_type_id_expression (expr.type_reference));
        }
 
index 89c878d47ab926848124233ffb3b5ce856f88f53..f28a168e833392b2ab63c2d90bbc0f2de8bf1aef 100644 (file)
@@ -187,6 +187,7 @@ TESTS = \
        control-semantic/printf-too-few.test \
        control-semantic/printf-too-many.test \
        control-semantic/variadic-argument-invalid.test \
+       enums/default-gtype.vala \
        enums/enum_only.vala \
        enums/enum-no-gtype.vala \
        enums/enums.vala \
@@ -205,6 +206,7 @@ TESTS = \
        structs/struct-static-field-initializer.test \
        structs/struct-static-property-initializer.test \
        structs/structs.vala \
+       structs/default-gtype.vala \
        structs/gvalue.vala \
        structs/bug530605.vala \
        structs/bug572091.vala \
@@ -378,6 +380,7 @@ TESTS = \
        objects/bug795521.vala \
        errors/catch-error-code.vala \
        errors/catch-in-finally.vala \
+       errors/default-gtype.vala \
        errors/errors.vala \
        errors/errorcode.vala \
        errors/errordomain.vala \
diff --git a/tests/enums/default-gtype.vala b/tests/enums/default-gtype.vala
new file mode 100644 (file)
index 0000000..152f723
--- /dev/null
@@ -0,0 +1,15 @@
+[CCode (has_type_id = false)]
+enum Foo {
+       MANAM
+}
+
+[CCode (has_type_id = false)]
+[Flags]
+enum Bar {
+       MANAM
+}
+
+void main () {
+       assert (typeof (Foo) == typeof (int));
+       assert (typeof (Bar) == typeof (uint));
+}
diff --git a/tests/errors/default-gtype.vala b/tests/errors/default-gtype.vala
new file mode 100644 (file)
index 0000000..e5fc98e
--- /dev/null
@@ -0,0 +1,7 @@
+errordomain Foo {
+       MANAM
+}
+
+void main () {
+       assert (typeof (Foo) == typeof (GLib.Error));
+}
diff --git a/tests/structs/default-gtype.vala b/tests/structs/default-gtype.vala
new file mode 100644 (file)
index 0000000..93b245b
--- /dev/null
@@ -0,0 +1,11 @@
+struct Foo {
+       public int field;
+}
+
+[CCode (has_type_id = false)]
+struct Bar : Foo {
+}
+
+void main () {
+       assert (typeof (Bar) == typeof (Foo));
+}