[a108] BoundFunc.MaxParams incorrect output

Report problems with documented functionality
User avatar
lvalkov
Posts: 56
Joined: 08 Mar 2019, 16:39

[a108] BoundFunc.MaxParams incorrect output

18 Jan 2020, 20:57

Querying MaxParams on any bound function object (created with Bind()) incorrectly* returns 0 instead of:
  1. the base function's actual parameter count; or
  2. the number of remaining unbound parameters (up to the variadic for variadic functions).

Code: Select all

f(a, b, c, d*)
{

}

f := Func('f')
MsgBox f.MaxParams ; 3, expected 3(A) or 3(B). Correct. Function not bound yet.

f := f.Bind('a')
MsgBox f.MaxParams ; 0, expected 3(A) or 2(B)

f := f.Bind('b')
MsgBox f.MaxParams ; 0, expected 3(A) or 1(B)

f := f.Bind('c')
MsgBox f.MaxParams ; 0, expected 3(A) or 0(B)

*Having it always return 0 is not particularly useful. I heavily doubt this was a conscious design decision.
Other methods (such as IsOptional() behave similarly. This evidently stems from the fact that they query the BoundFunc interface instead of the underlying function's. Again, not particularly useful.
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [a108] BoundFunc.MaxParams incorrect output

07 Feb 2020, 23:22

It is a conscious design choice, and is directly comparable to a user-defined implementation of a bound function.

Consider

Code: Select all

f1(p*) => f2(p*)
f1 has no maximum parameter count, but it will still fail if you pass more parameters than f2 can accept.

The BoundFunc type also covers ObjBindMethod. In that case, there may be no target function. Even knowing the target object and method name, it may be impossible to determine the maximum parameter count (although it's more likely possible in v2 than in v1).

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests