[vala] Fix assignment to array fields using array_length_type



commit e754e9123fa17ce2324c9fe2954e0f338bca1486
Author: Jürg Billeter <j bitron ch>
Date:   Fri Apr 9 09:16:40 2010 +0200

    Fix assignment to array fields using array_length_type
    
    Fixes bug 614919.

 codegen/valaccodearraymodule.vala |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 01bf85f..e8e125f 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -313,7 +313,16 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 						}
 
 						if (field.array_length_type != null) {
-							length_expr = new CCodeCastExpression (length_expr, "gint");
+							// cast if field does not use int for array length
+							var parent_expr = array_expr.parent_node as Expression;
+							if (array_expr.lvalue) {
+								// don't cast if array is used as lvalue
+							} else if (parent_expr != null && parent_expr.symbol_reference is ArrayLengthField &&
+								   parent_expr.lvalue) {
+								// don't cast if array length is used as lvalue
+							} else {
+								length_expr = new CCodeCastExpression (length_expr, "gint");
+							}
 						}
 					} else {
 						length_expr = new CCodeIdentifier (get_array_length_cname (field.get_cname (), dim));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]