Skip to content

Normalise stdlib error message formats to match PUC-Lua #252

@davydog187

Description

@davydog187

Problem

Several Lua 5.3 suite files (math.lua, sort.lua, errors.lua, strings.lua, goto.lua) use a checkerror(msg, f, ...) helper that calls pcall(f, ...) and asserts string.find(err, msg) matches a specific substring. We produce the right error category but the wrong phrasing, so dozens of assertions fail.

Concrete templates to match

  • "wrong number of arguments to 'X'" — when too few/many args (e.g. table.insert({}, 2, 3, 4)). One case already fixed in suite: triage and promote literals/goto/events/nextvar files #251.
  • "bad argument #N to 'X' (T expected, got T)" — verify the exact wording across all stdlib argument-error sites.
  • "attempt to perform 'n//0'" — integer divide-by-zero (op token included).
  • "... has no integer representation" — float-to-int conversions (f | 1, f >> 0, bitwise on non-representable floats).
  • "field 'X'" prefix when arithmetic/indexing fails on a global access (e.g. math.huge << 1"field 'huge'").

Why it matters

This is the biggest single lever for suite progress. Likely unlocks 60–150 individual asserts across at least 4 suite files. The work is mechanical: identify each raise site in lib/lua/vm/stdlib* and lib/lua/vm/executor.ex, compare wording to PUC-Lua's luaL_error/luaL_argerror output, adjust.

Suggested approach

  1. Audit the existing Lua.VM.ArgumentError template in lib/lua/vm/argument_error.ex against PUC-Lua's luaL_argerror format.
  2. Add a single helper for "wrong number of arguments to 'X'" and route variadic stdlib functions through it.
  3. For arithmetic-on-globals errors, attach the field hint that :get_field/:get_global already tracks.
  4. Pin each template with a unit test under test/lua/vm/ so the wording is enforced.

Acceptance

  • New unit tests pinning each error template.
  • Re-running the suite shows progress in math.lua, sort.lua, errors.lua, strings.lua (some still deferred for other reasons, but their checkerror ranges should shrink or pass).

Metadata

Metadata

Assignees

No one assigned

    Labels

    direction:ADirection A: suite triage to 0.5.0kind:suiteLua 5.3 official test suite work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions