]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support implicit GValue conversion when assigning to properties
authorLuca Bruno <lethalman88@gmail.com>
Thu, 10 Jun 2010 09:00:13 +0000 (11:00 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 21 Aug 2010 08:47:21 +0000 (10:47 +0200)
Thanks to Michal Hruby for the test case.

Fixes bug 620706.

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/objects/bug620706.vala [new file with mode: 0644]

index bf7703e91ff6d5a2bfe290650dd74cd68f7830a1..6a17886dc423a0af52946d3089fd35fe9a88da08 100644 (file)
@@ -5484,6 +5484,11 @@ public class Vala.CCodeBaseModule : CodeGenerator {
         * from a vala to C point of view all expressions denoting locals, fields and
         * parameters are eligable to an ADDRESS_OF operator */
        public bool is_address_of_possible (Expression e) {
+               if (gvalue_type != null && e.target_type.data_type == gvalue_type && e.value_type.data_type != gvalue_type) {
+                       // implicit conversion to GValue is not addressable
+                       return false;
+               }
+
                var ma = e as MemberAccess;
 
                if (ma == null) {
@@ -5502,7 +5507,14 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                }
 
                var ccomma = new CCodeCommaExpression ();
-               var temp_decl = get_temp_variable (e.value_type, true, null, false);
+               DataType address_of_type;
+               if (gvalue_type != null && e.target_type != null && e.target_type.data_type == gvalue_type) {
+                       // implicit conversion to GValue
+                       address_of_type = e.target_type;
+               } else {
+                       address_of_type = e.value_type;
+               }
+               var temp_decl = get_temp_variable (address_of_type, true, null, false);
                var ctemp = get_variable_cexpression (temp_decl.name);
                temp_vars.add (temp_decl);
                ccomma.append_expression (new CCodeAssignment (ctemp, ce));
index 24304071b30384c46392e699e210592318e170ab..b24ea23ec60e0e81bc9882a057c8bd2562bec4de 100644 (file)
@@ -69,6 +69,7 @@ TESTS = \
        objects/bug597155.vala \
        objects/bug597161.vala \
        objects/bug613486.vala \
+       objects/bug620706.vala \
        errors/errors.vala \
        errors/bug567181.vala \
        errors/bug579101.vala \
diff --git a/tests/objects/bug620706.vala b/tests/objects/bug620706.vala
new file mode 100644 (file)
index 0000000..7ac4bc9
--- /dev/null
@@ -0,0 +1,13 @@
+class Foo : Object {
+       public Value val { get; set; }
+}
+
+struct Bar {
+       int dummy;
+}
+
+void main () {
+       var f = new Foo ();
+       var b = Bar ();
+       f.val = b;
+}