Skip to content

Commit

Permalink
Fix binding parameters to functions with more than two parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed May 27, 2023
1 parent 598c8f8 commit 7234fee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public int invokeBind(Frame frame, FunctionHandle hFunc, ObjectHandle hArg, int
ixPrev = ix;
if (fAdjust)
{
ix--;
ix -= i;
}
hFuncR = hFuncR.bind(frameCaller, ix, ahValue[i]);
}
Expand Down
28 changes: 19 additions & 9 deletions manualTests/src/main/x/reflect.x
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,33 @@ module TestReflection

console.print("\n** testBind");

function void (Int, String) log =
(i, v) -> console.print($"[{i}] {v}");
function void (Int, String, Boolean) log =
(i, v, f) -> console.print($"[{i}] {v} {f}");

Parameter<Int> param0 = log.params[0].as(Parameter<Int>);
Parameter<String> param1 = log.params[1].as(Parameter<String>);
Parameter<Int> param0 = log.params[0].as(Parameter<Int>);
Parameter<String> param1 = log.params[1].as(Parameter<String>);
Parameter<Boolean> param2 = log.params[2].as(Parameter<Boolean>);

// single bind
function void (Int) hello = log.bind(param1, "hello").as(function void (Int));
hello(0);
function void (Int, Boolean) hello = log.bind(param1, "hello").as(function void (Int, Boolean));
hello(0, True);

// multi bind
// multi partial bind
Map<Parameter, Object> paramsPartial = new ListMap();
paramsPartial.put(param0, 1);
paramsPartial.put(param1, "world");

function void (Boolean) fnPartial = log.bind(paramsPartial).as(function void (Boolean));
fnPartial(True);

// multi full bind
Map<Parameter, Object> params = new ListMap();
params.put(param0, 1);
params.put(param1, "world");
params.put(param2, True);

function void () world = log.bind(params);
world();
function void () fn = log.bind(params);
fn();
}

void testChildTypes()
Expand Down

0 comments on commit 7234fee

Please sign in to comment.