瀏覽代碼

Apply default arguement code to dynamic functions too. Closes https://github.com/HaxeFoundation/hxcpp/issues/189

Hugh 10 年之前
父節點
當前提交
e167230369
共有 2 個文件被更改,包括 20 次插入2 次删除
  1. 8 2
      gencpp.ml
  2. 12 0
      tests/unit/src/unit/hxcpp_issues/Issue189.hx

+ 8 - 2
gencpp.ml

@@ -2565,13 +2565,19 @@ let gen_field ctx class_def class_name ptr_name dot_name is_static is_interface
          let func_name = "__default_" ^ (remap_name) in
          output ("HX_BEGIN_DEFAULT_FUNC(" ^ func_name ^ "," ^ class_name ^ ")\n");
          output return_type;
-         output (" run(" ^ (gen_arg_list function_def.tf_args "") ^ ")");
+         output (" run(" ^ (gen_arg_list function_def.tf_args "__o_") ^ ")");
          ctx.ctx_dump_src_pos <- dump_src;
          if (is_void) then begin
-            ctx.ctx_writer#begin_block;
+            ctx.ctx_writer#begin_block;  
+            generate_default_values ctx function_def.tf_args "__o_";
             gen_expression ctx false function_def.tf_expr;
             output "return null();\n";
             ctx.ctx_writer#end_block;
+         end else if (has_default_values function_def.tf_args) then begin
+            ctx.ctx_writer#begin_block;  
+            generate_default_values ctx function_def.tf_args "__o_";
+            gen_expression ctx false function_def.tf_expr;
+            ctx.ctx_writer#end_block;
          end else
             gen_expression ctx false (to_block function_def.tf_expr);
 

+ 12 - 0
tests/unit/src/unit/hxcpp_issues/Issue189.hx

@@ -0,0 +1,12 @@
+package unit.hxcpp_issues;
+
+
+class Issue189 extends Test {
+   function dynamicWidthDefaults(first=true, second=6, third=10.5) : Float {
+      return first ? second : third;
+   }
+	function test() {
+		eq(dynamicWidthDefaults(),10.5);
+	}
+}
+