Skip to content

errors: thread operand hints into arith & bitwise type errors#270

Merged
davydog187 merged 2 commits into
mainfrom
errors/arith-bitwise-hints
May 28, 2026
Merged

errors: thread operand hints into arith & bitwise type errors#270
davydog187 merged 2 commits into
mainfrom
errors/arith-bitwise-hints

Conversation

@davydog187
Copy link
Copy Markdown
Contributor

Summary

Closes the remaining half of #252 — the wording already matched PUC-Lua;
only the trailing (global 'X') / (local 'X') / (upvalue 'X') /
(field 'X') hint suffix was missing.

  • Codegen: every arithmetic / bitwise binop / unop now resolves its
    operands' lexical origin via the existing name_hint/2 and bakes the
    result into the instruction tuple. Same pattern as :get_field,
    :set_field, :call, :self.
  • Executor: raise_arith_type_error/4, to_integer!/4, and
    float_to_integer!/3 now take a hint and append it via
    format_target_hint/1. The safe_* helpers pick the failing
    operand's hint correctly.
  • Dispatcher (B5d v2): bytecode encoding preserves hints, and
    dispatcher_binop / dispatcher_unop thread them through to the
    same raise paths — so compiled prototypes also surface the hint.
  • Suite skips: math.lua / sort.lua / errors.lua /
    strings.lua skip reasons updated to drop the now-resolved
    "checkerror format mismatch" blocker. Remaining blockers are
    behavioural (finite math.huge, timeouts, parse-error templates)
    and tracked separately.

Examples

Expression Before After
return foo + 1 (foo nil global) arithmetic on a nil value arithmetic on a nil value (global 'foo')
local x; return -x arithmetic on a nil value arithmetic on a nil value (local 'x')
local t={}; return t.x + 1 arithmetic on a nil value arithmetic on a nil value (field 'x' on local 't')
return math.huge << 1 number has no integer representation number has no integer representation (field 'huge' on global 'math')
local s='x'; return s << 1 bitwise operation on a string value bitwise operation on a string value (local 's')

Test plan

  • mix test — 1963 passed (was 1955), 25 skipped — 8 new pin tests
    for the hint suffix across all four origin tags × arithmetic /
    bitwise / integer-representation.
  • mix format --check-formatted
  • mix compile --warnings-as-errors
  • mix dialyzer — no new errors (pre-existing one in
    tasks/suite_runner.ex unchanged).
  • test/lua/vm/error_format_test.exsarithmetic type error carries operand hint + bitwise type error carries operand hint
    describe blocks pin every rendering.

Closes #252.
Plan: A40

Append PUC-Lua-style `(global 'X')` / `(local 'X')` / `(upvalue 'X')` /
`(field 'X')` suffixes to arithmetic and bitwise type errors and to
"number has no integer representation" failures. Closes the remaining
half of #252 — wording already matched; only the trailing hint was
missing.

Codegen now resolves each binop / unop operand AST node to a hint
tuple via the existing `name_hint/2` and bakes it into the instruction
tuple (same pattern as `:get_field` / `:call`). The executor and the
v2 dispatcher both thread the hint of the failing operand into the
raise helpers; `format_target_hint/1` renders the suffix.

Bytecode encoding preserves hints, so on-disk prototypes keep the
suffix on errors. Encoded tuple shape changes are isolated to the
14 affected opcodes.

Updates skip reasons for math.lua / sort.lua / errors.lua /
strings.lua to drop the now-resolved "checkerror format mismatch"
blocker. Remaining blockers there are behavioural (finite math.huge,
timeouts, parse-error templates) and tracked separately.

Plan: A40
Closes #252
@davydog187 davydog187 merged commit e8b9c4d into main May 28, 2026
5 checks passed
@davydog187 davydog187 deleted the errors/arith-bitwise-hints branch May 28, 2026 11:37
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.

Normalise stdlib error message formats to match PUC-Lua

1 participant