[vala] Fix calling generic instance methods



commit 3b07e99b6d3abb0be4cc39b835fd43536999f1e2
Author: Jürg Billeter <j bitron ch>
Date:   Fri Sep 25 11:16:53 2009 +0200

    Fix calling generic instance methods
    
    Fixes bug 596246.

 codegen/valaccodebasemodule.vala       |   20 +++++++++++---------
 codegen/valaccodemethodcallmodule.vala |    4 ++--
 2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 25cdbe3..cd7dae6 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3511,9 +3511,10 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 	public virtual void generate_error_domain_declaration (ErrorDomain edomain, CCodeDeclarationSpace decl_space) {
 	}
 
-	public void add_generic_type_arguments (CCodeFunctionCall ccall, Gee.List<DataType> type_args, CodeNode expr, bool is_chainup = false) {
+	public void add_generic_type_arguments (Map<int,CCodeExpression> arg_map, Gee.List<DataType> type_args, CodeNode expr, bool is_chainup = false) {
+		int type_param_index = 0;
 		foreach (var type_arg in type_args) {
-			ccall.add_argument (get_type_id_expression (type_arg, is_chainup));
+			arg_map.set (get_param_pos (0.1 * type_param_index + 0.01), get_type_id_expression (type_arg, is_chainup));
 			if (requires_copy (type_arg)) {
 				var dup_func = get_dup_func_expression (type_arg, type_arg.source_reference, is_chainup);
 				if (dup_func == null) {
@@ -3521,12 +3522,13 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 					expr.error = true;
 					return;
 				}
-				ccall.add_argument (new CCodeCastExpression (dup_func, "GBoxedCopyFunc"));
-				ccall.add_argument (get_destroy_func_expression (type_arg, is_chainup));
+				arg_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeCastExpression (dup_func, "GBoxedCopyFunc"));
+				arg_map.set (get_param_pos (0.1 * type_param_index + 0.03), get_destroy_func_expression (type_arg, is_chainup));
 			} else {
-				ccall.add_argument (new CCodeConstant ("NULL"));
-				ccall.add_argument (new CCodeConstant ("NULL"));
+				arg_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeConstant ("NULL"));
+				arg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeConstant ("NULL"));
 			}
+			type_param_index++;
 		}
 	}
 
@@ -3587,12 +3589,12 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 			generate_type_declaration (expr.type_reference, source_declarations);
 
+			var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
+
 			if (cl != null && !cl.is_compact) {
-				add_generic_type_arguments (creation_call, expr.type_reference.get_type_arguments (), expr);
+				add_generic_type_arguments (carg_map, expr.type_reference.get_type_arguments (), expr);
 			}
 
-			var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
-
 			bool ellipsis = false;
 
 			int i = 1;
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 70483ef..5baa63a 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -108,13 +108,13 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
 			foreach (DataType base_type in current_class.get_base_types ()) {
 				if (base_type.data_type is Class) {
-					add_generic_type_arguments (ccall, base_type.get_type_arguments (), expr, true);
+					add_generic_type_arguments (in_arg_map, base_type.get_type_arguments (), expr, true);
 					break;
 				}
 			}
 		} else if (m != null && m.get_type_parameters ().size > 0) {
 			// generic method
-			add_generic_type_arguments (ccall, ma.get_type_arguments (), expr);
+			add_generic_type_arguments (in_arg_map, ma.get_type_arguments (), expr);
 		}
 
 		// the complete call expression, might include casts, comma expressions, and/or assignments



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