From: Luca Bruno Date: Thu, 10 Jun 2010 09:00:13 +0000 (+0200) Subject: Support implicit GValue conversion when assigning to properties X-Git-Tag: 0.9.8~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5600b43e1932626632e298b0b63eb91ba9443fd7;p=thirdparty%2Fvala.git Support implicit GValue conversion when assigning to properties Thanks to Michal Hruby for the test case. Fixes bug 620706. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index bf7703e91..6a17886dc 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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)); diff --git a/tests/Makefile.am b/tests/Makefile.am index 24304071b..b24ea23ec 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..7ac4bc90b --- /dev/null +++ b/tests/objects/bug620706.vala @@ -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; +}