[vala/0.34] codegen: Fix instance parameter for property setter in SimpleType structs
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.34] codegen: Fix instance parameter for property setter in SimpleType structs
- Date: Wed, 1 Mar 2017 08:57:02 +0000 (UTC)
commit 932abc3f8d2d539812752c3f276a098ebbb22d75
Author: Nikolay Orlyuk <virkony gmail com>
Date: Tue Feb 19 02:35:29 2013 +0200
codegen: Fix instance parameter for property setter in SimpleType structs
Add test-case and fix code generator for call to the setter to pass
instance as a value rather than as a pointer to value.
Based on patches by Nathan Summers.
https://bugzilla.gnome.org/show_bug.cgi?id=657346
codegen/valaccodebasemodule.vala | 4 ++--
tests/Makefile.am | 1 +
tests/structs/bug694140.vala | 23 +++++++++++++++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3d92f57..5f9b629 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5862,8 +5862,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
/* target instance is first argument */
var cinstance = (CCodeExpression) get_ccodenode (instance);
- if (prop.parent_symbol is Struct) {
- // we need to pass struct instance by reference
+ if (prop.parent_symbol is Struct && !((Struct) prop.parent_symbol).is_simple_type ())
{
+ // we need to pass struct instance by reference if it isn't a simple-type
var instance_value = instance.target_value;
if (!get_lvalue (instance_value)) {
instance_value = store_temp_value (instance_value, instance);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e6fe0f7..760ca96 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -118,6 +118,7 @@ TESTS = \
structs/bug685177.vala \
structs/bug686190.vala \
structs/bug690380.vala \
+ structs/bug694140.vala \
structs/bug749952.vala \
structs/bug775761.vala \
delegates/delegates.vala \
diff --git a/tests/structs/bug694140.vala b/tests/structs/bug694140.vala
new file mode 100644
index 0000000..18368a9
--- /dev/null
+++ b/tests/structs/bug694140.vala
@@ -0,0 +1,23 @@
+string[] colors;
+
+[SimpleType]
+[CCode (has_type_id = false)]
+struct Foo : int {
+ public string bar {
+ get {
+ return colors[(int) this];
+ }
+ set {
+ colors[(int) this] = value;
+ }
+ }
+}
+
+void main () {
+ colors = { "black", "red", "green", "blue" };
+
+ Foo foo = 1;
+ assert (foo.bar == "red");
+ foo.bar = "white";
+ assert (foo.bar == "white");
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]