[vala/0.34] codegen: Don't return void for non-nullable simple-type structs
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.34] codegen: Don't return void for non-nullable simple-type structs
- Date: Wed, 1 Mar 2017 09:44:12 +0000 (UTC)
commit 3b38bf1e9cf9074dea2ce95bbb83e6b963ee3039
Author: Michael James Gratton <mike vee net>
Date: Mon Feb 6 16:47:21 2017 +1100
codegen: Don't return void for non-nullable simple-type structs
https://bugzilla.gnome.org/show_bug.cgi?id=778224
codegen/valaccodebasemodule.vala | 11 ++++++++++-
tests/Makefile.am | 1 +
tests/errors/bug778224.vala | 26 ++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index df8c661..25e2c0d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -6558,7 +6558,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
public void return_default_value (DataType return_type) {
- ccode.add_return (default_value_for_type (return_type, false));
+ var st = return_type.data_type as Struct;
+ if (st != null && st.is_simple_type () && !return_type.nullable) {
+ // 0-initialize struct with struct initializer { 0 }
+ // only allowed as initializer expression in C
+ var ret_temp_var = get_temp_variable (return_type, true, null, true);
+ emit_temp_var (ret_temp_var);
+ ccode.add_return (new CCodeIdentifier (ret_temp_var.name));
+ } else {
+ ccode.add_return (default_value_for_type (return_type, false));
+ }
}
public virtual void generate_dynamic_method_wrapper (DynamicMethod method) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 760ca96..7f984ef 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -182,6 +182,7 @@ TESTS = \
errors/bug623049.vala \
errors/bug639589.vala \
errors/bug651145.vala \
+ errors/bug778224.vala \
asynchronous/bug595735.vala \
asynchronous/bug595755.vala \
asynchronous/bug596177.vala \
diff --git a/tests/errors/bug778224.vala b/tests/errors/bug778224.vala
new file mode 100644
index 0000000..3a61a02
--- /dev/null
+++ b/tests/errors/bug778224.vala
@@ -0,0 +1,26 @@
+errordomain FooError {
+ BAR;
+}
+
+[SimpleType]
+struct Foo {
+ int i;
+}
+
+bool @true = true;
+
+Foo foo () throws FooError {
+ if (@true) {
+ throw new FooError.BAR ("");
+ }
+
+ return { 1 };
+}
+
+void main () {
+ try {
+ foo ();
+ } catch {
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]