google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

UnpackArgs has different behavior for `args` vs `kwargs` #544

Closed nicks closed 1 month ago

nicks commented 1 month ago

Repro steps:

  1. Define a built-in function with UnpackArgs used like this:
if err := starlark.UnpackArgs("unpack", args, kwargs,
    "x", &x, "y?", &y, "z", &z); err != nil {
  t.Errorf("UnpackArgs failed: %v", err)
}
  1. Pass two arguments to this function as named args:
f(1, 2)

This is OK.

  1. Pass two arguments to this function as positional args:
f(x=1, y=2)

Expected result:

This should succeed. y is optional, so z should also be optional

Actual result:

UnpackArgs failed: unpack: missing argument for z

Additional info

I have a test in a branch that demonstrates the problem, might also open a PR if the fix is easy.

adonovan commented 1 month ago

Did you mean starlark.UnpackArgs("unpack", args, kwargs, ...?

nicks commented 1 month ago

oops, yes, fixed!