Skip to content

Fix false "Expected at most 2 arguments" error for variadic min()/max() - #9120

Merged
limzykenneth merged 2 commits into
processing:mainfrom
xdroberto:fix-min-max-variadic-validation
Sep 1, 2026
Merged

Fix false "Expected at most 2 arguments" error for variadic min()/max()#9120
limzykenneth merged 2 commits into
processing:mainfrom
xdroberto:fix-min-max-variadic-validation

Conversation

@xdroberto

Copy link
Copy Markdown
Contributor

Resolves #9039

Changes:

The runtime implementation of min() and max() is variadic, but their documented overloads only declared (n0, n1), so the FES parameter validator (which derives its Zod schemas from the inline reference via docs/parameterData.json) rejected calls like min(1, 2, 3, 4) with a false "Expected at most 2 arguments, but received more in min()". This restores the 1.x behavior (the 1.x version of this same problem was fixed in #4890).

  • Added a @param {...Number} rest parameter to the two-number overload of both min() and max() in src/math/calculation.js, following the existing pattern used by createVector().
  • Updated docs/parameterData.json so the first overload reads ["Number", "Number", "...Number[]"] for both functions. I edited just these two entries by hand: running the full npm run docs locally reorders hundreds of unrelated entries (the checked-in file seems out of sync with a full regeneration), which would have buried the actual change. I did verify that a full regeneration produces exactly these values for min/max — happy to commit the fully regenerated file instead if you prefer.
  • Added a "variadic min/max" suite to test/unit/core/param_errors.js covering both functions (valid: two numbers, more than two numbers, a single array; invalid: no arguments, a single number, a non-number among the arguments).

Following up on @limzykenneth's notes in the issue:

  • With only number arguments, at least 2 are still required: min() and min(5) still fail validation, and the friendly error message is byte-identical to the current behavior (I compared the old and new schemas side by side).
  • The single-array overload min([1, 2, 3]) is unchanged and still valid.
  • The rest parameter translated cleanly to FES validation — no changes to param_validator.js were needed, since it already supports rest parameters (...Number[]) via z.tuple's rest argument.
  • A wrong type among the extra arguments is reported with its position, e.g. min(1, 2, '3', 4)"Expected number at the third parameter, but received string in min()".

Test results: test/unit/math/ + test/unit/core/ — 646 passed, 0 failed.

PR Checklist

…/max()

The runtime implementation of min() and max() is variadic, but their
documented overloads only declared (n0, n1), so the parameter validator
rejected calls like min(1, 2, 3, 4). Add a {...Number} rest parameter to
the two-number overload of both functions (same pattern as createVector)
and update parameterData.json accordingly.

Calls with fewer than two number arguments still fail validation with
the same friendly error as before, and the single-array overload is
unchanged.
@p5-bot

p5-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: b268ac0

Previous deployments

0163391


This is an automated message.

@limzykenneth
limzykenneth merged commit ce75065 into processing:main Sep 1, 2026
4 checks passed
@limzykenneth

Copy link
Copy Markdown
Member

Looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: min/max function with variable length parametes

2 participants