Skip to content

Commit

Permalink
[cs] Add C# optional arguments on Haxe-defined functions that have op…
Browse files Browse the repository at this point in the history
…tional arguments

Closes #4147
  • Loading branch information
waneck committed Jun 25, 2017
1 parent 6046ad7 commit 261e73c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/generators/gencs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,9 @@ let generate con =
(* <T>(string arg1, object arg2) with T : object *)
(match cf.cf_expr with
| Some { eexpr = TFunction tf } ->
print w "%s(%s)%s" (params) (String.concat ", " (List.map2 (fun (var, _) (_,_,t) -> sprintf "%s %s" (argt_s t) (change_id var.v_name)) tf.tf_args args)) (params_ext)
print w "%s(%s)%s" (params) (String.concat ", "
(List.map2 (fun (var,o) (_,_,t) -> sprintf "%s %s%s" (argt_s t) (change_id var.v_name) (if is_some o then " = default(" ^ t_s var.v_type ^ ")" else "")) tf.tf_args args)
) (params_ext)
| _ ->
print w "%s(%s)%s" (params) (String.concat ", " (List.map (fun (name, _, t) -> sprintf "%s %s" (argt_s t) (change_id name)) args)) (params_ext)
);
Expand Down

3 comments on commit 261e73c

@nadako
Copy link
Member

@nadako nadako commented on 261e73c Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I'm now getting error CS1737: Optional parameter cannot precede required parameters because of this.

@nadako
Copy link
Member

@nadako nadako commented on 261e73c Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this doesn't play well with static ctors:

class Main {
	function new(some = 1) {
	}
}
public Main(global::haxe.lang.Null<int> some) {
	global::Main.__hx_ctor__Main(this, some);
}
	
	
protected static void __hx_ctor__Main(global::Main __hx_this, global::haxe.lang.Null<int> some = default(global::haxe.lang.Null<int>)) {
}

@nadako
Copy link
Member

@nadako nadako commented on 261e73c Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if better solution would be to generate overloads to properly support optional arg skipping? Anyway, I had to revert this locally for now...

Please sign in to comment.