Skip to content

Honor __lt when selecting math.min and math.max - #315

Open
XinyuGuan wants to merge 1 commit into
xacrimon:mainfrom
XinyuGuan:fix/min-max-ordering
Open

XinyuGuan wants to merge 1 commit into
xacrimon:mainfrom
XinyuGuan:fix/min-max-ordering

Conversation

@XinyuGuan

Copy link
Copy Markdown

Fixes #313.

math.min and math.max now fall back to the VM's __lt lookup when a pair cannot use primitive ordering. The numeric/string path, exact mixed integer/float comparisons from #142, first-argument checks, tie handling and original result identity are retained.

The fallback uses the existing async-native machinery. Arguments stay rooted in the native stack window; only slot indices cross calls, and only the comparator's first result is interpreted using Lua truthiness.

Adds eight regression cases checked against PUC Lua 5.5.1: tables and userdata, right-operand lookup/mixed types, truthiness, error-object propagation, GC and reentrant selection, live metatable changes, ties, and primitive/single-argument controls. Seven fail before the fix; all eight pass afterward.

Validation with the pinned Rust nightly 2026-04-05, Linux amd64:

  • Full upstream CI command set passes: workspace tests, formatting, workspace/all-target Clippy, generic-table Clippy, and generic-table unit tests.
  • All eight regressions pass in release mode and in a second clean checkout with the exact patch applied.
  • The rebuilt CLI matches reference output for all eight programs, twice each. Additional comparisons cover a transition from primitive to metamethod ordering and a callable-table comparator.
  • git diff --check passes.

This branch is based directly on upstream main and is independent of the unpack fix in #314.

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.

math.min and math.max omit the __lt metamethod fallback

1 participant