summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-03-01 09:45:56 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-03-01 09:45:56 +0100
commitfd487e0292f4e17f54a4adbf4d6bb37c1359620e (patch)
tree2f0310344d16fa829e5e00fa4101ae7c10c82095
parent8629327cac8571bb71d19ec1ce683e24781beb3e (diff)
downloadvala-fd487e0292f4e17f54a4adbf4d6bb37c1359620e.tar.gz
codegen: Include "glib-object.h" for typeof expression
-rw-r--r--codegen/valaccodebasemodule.vala2
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/enums/default-gtype.vala15
-rw-r--r--tests/errors/default-gtype.vala7
-rw-r--r--tests/structs/default-gtype.vala11
5 files changed, 38 insertions, 0 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index b7d0de010..acbb763ce 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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));
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 89c878d47..f28a168e8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..152f72372
--- /dev/null
+++ b/tests/enums/default-gtype.vala
@@ -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
index 000000000..e5fc98ea7
--- /dev/null
+++ b/tests/errors/default-gtype.vala
@@ -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
index 000000000..93b245b64
--- /dev/null
+++ b/tests/structs/default-gtype.vala
@@ -0,0 +1,11 @@
+struct Foo {
+ public int field;
+}
+
+[CCode (has_type_id = false)]
+struct Bar : Foo {
+}
+
+void main () {
+ assert (typeof (Bar) == typeof (Foo));
+}