generate casts for property assignments where necessary, fixes bug 511732
authorJuerg Billeter <j@bitron.ch>
Fri, 15 Feb 2008 12:08:48 +0000 (12:08 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 15 Feb 2008 12:08:48 +0000 (12:08 +0000)
2008-02-15  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodeassignmentbinding.vala,
  gobject/valaccodegenerator.vala: generate casts for property
  assignments where necessary, fixes bug 511732

svn path=/trunk/; revision=1011

ChangeLog
gobject/valaccodeassignmentbinding.vala
gobject/valaccodegenerator.vala

index e87190e..9bd7bff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-02-15  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodeassignmentbinding.vala,
+         gobject/valaccodegenerator.vala: generate casts for property
+         assignments where necessary, fixes bug 511732
+
+2008-02-15  Jürg Billeter  <j@bitron.ch>
+
        * vala/valamethod.vala, vala/valasemanticanalyzer.vala,
          gobject/valaccodegenerator.vala: fix memory management of
          parameters with ownership transfer, fixes bug 511642
index 312be4d..b2098af 100644 (file)
@@ -69,11 +69,12 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
                } else {
                        CCodeExpression cexpr = (CCodeExpression) assignment.right.ccodenode;
 
+                       // ensure to pass the value correctly typed (especially important for varargs)
+                       cexpr = codegen.get_implicit_cast_expression (cexpr, assignment.right.static_type, prop.type_reference);
+
                        if (!prop.no_accessor_method) {
                                if (prop.type_reference.is_real_struct_type ()) {
-                                       cexpr = codegen.get_address_of_expression (assignment.right, codegen.get_implicit_cast_expression (cexpr, assignment.right.static_type, prop.type_reference));
-                               } else {
-                                       cexpr = codegen.get_implicit_cast_expression (cexpr, assignment.right.static_type, prop.type_reference);
+                                       cexpr = codegen.get_address_of_expression (assignment.right, cexpr);
                                }
                        }
 
index 8b2f37f..4f63697 100644 (file)
@@ -3086,8 +3086,14 @@ public class Vala.CCodeGenerator : CodeGenerator {
 
                if (context.checking && target_type.data_type != null && target_type.data_type.is_subtype_of (gtypeinstance_type)) {
                        return new InstanceCast (cexpr, target_type.data_type);
-               } else if (target_type.data_type != null && target_type.data_type.is_reference_type () && expression_type.get_cname () != target_type.get_cname ()) {
-                       return new CCodeCastExpression (cexpr, target_type.get_cname ());
+               } else if (target_type.data_type != null && expression_type.get_cname () != target_type.get_cname ()) {
+                       var st = target_type.data_type as Struct;
+                       if (target_type.data_type.is_reference_type () || (st != null && st.is_simple_type ())) {
+                               // don't cast non-simple structs
+                               return new CCodeCastExpression (cexpr, target_type.get_cname ());
+                       } else {
+                               return cexpr;
+                       }
                } else if (target_type is DelegateType && expression_type is MethodType) {
                        var dt = (DelegateType) target_type;
                        var mt = (MethodType) expression_type;