Browse Source

[python] handle special arguments (args, kwargs) for constructor calls as well (closes #5737)

Dan Korostelev 9 years ago
parent
commit
143be6fd7e
2 changed files with 23 additions and 1 deletions
  1. 1 1
      src/generators/genpy.ml
  2. 22 0
      tests/unit/src/unit/issues/Issue5737.hx

+ 1 - 1
src/generators/genpy.ml

@@ -1321,7 +1321,7 @@ module Printer = struct
 				print_call pctx e1 el e
 			| TNew(c,_,el) ->
 				let id = print_base_type (t_infos (TClassDecl c)) in
-				Printf.sprintf "%s(%s)" id (print_exprs pctx ", " el)
+				Printf.sprintf "%s(%s)" id (print_call_args pctx e el)
 			| TUnop(Not,Prefix,e1) ->
 				Printf.sprintf "(%s%s)" (print_unop Not) (print_expr pctx e1)
 			| TUnop(op,Prefix,e1) ->

+ 22 - 0
tests/unit/src/unit/issues/Issue5737.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+#if python
+private class C {
+	public var v:Array<Int>;
+	public var k:{a:Int};
+	public function new(v:python.VarArgs<Int>, k:python.KwArgs<{a:Int}>) {
+		this.v = v.toArray();
+		this.k = k.typed();
+	}
+}
+#end
+
+class Issue5737 extends Test {
+	#if python
+	function test(){
+		var c = new C([1,2,3], {a: 42});
+		aeq(c.v, [1,2,3]);
+		eq(c.k.a, 42);
+	}
+	#end
+}