]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix instance parameter for property setter in SimpleType structs
authorNikolay Orlyuk <virkony@gmail.com>
Tue, 19 Feb 2013 00:35:29 +0000 (02:35 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 24 Feb 2017 14:08:25 +0000 (15:08 +0100)
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
tests/Makefile.am
tests/structs/bug694140.vala [new file with mode: 0644]

index 6a18b881b5757e7e9fc9edbe5022c2fc541881f1..880e8a2d0e161f122d67b067df6c45dca7233a67 100644 (file)
@@ -5921,8 +5921,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);
index 268409bc0dc3834e3ad6b0b72e34d5b2c2653d81..666f11011b9f05c019814265bcc0c3cf00add4a6 100644 (file)
@@ -130,6 +130,7 @@ TESTS = \
        structs/bug685177.vala \
        structs/bug686190.vala \
        structs/bug690380.vala \
+       structs/bug694140.vala \
        structs/bug749952.vala \
        structs/bug775761.vala \
        structs/bug777194.vala \
diff --git a/tests/structs/bug694140.vala b/tests/structs/bug694140.vala
new file mode 100644 (file)
index 0000000..18368a9
--- /dev/null
@@ -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");
+}