Skip to content

Fix list_ops.vera runtime failure — built-in name shadowing (#154)#189

Merged
aallan merged 1 commit into
mainfrom
feature/fix-list-ops-runtime
Mar 3, 2026
Merged

Fix list_ops.vera runtime failure — built-in name shadowing (#154)#189
aallan merged 1 commit into
mainfrom
feature/fix-list-ops-runtime

Conversation

@aallan

@aallan aallan commented Mar 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixed: built-in intrinsic handlers (like length) in vera/wasm/calls.py unconditionally intercepted calls by function name, even when the user defined their own function with that name. User-defined functions now take priority over built-in intrinsics.
  • Root cause: The array-length built-in assumed an (i32, i32) pair on the WASM stack, but a user-defined length(@List<Int> -> @Nat) passes a single i32 ADT pointer, producing invalid WASM.
  • Guard: All 9 built-in handlers are now wrapped in if call.name not in self._known_fns:, so user definitions always shadow built-ins.

Test plan

  • vera run examples/list_ops.vera returns 60 (was crashing with type mismatch)
  • 3 new tests in TestBuiltinShadowing (user-defined length over ADT, single element, built-in still works)
  • test_list_ops_example_file upgraded from compile-only to runtime assertion
  • All 1,347 tests pass, mypy clean, all 15 examples pass

Closes #154

Generated with Claude Code

User-defined functions now take priority over built-in intrinsics in
WASM codegen. The built-in length(array) handler unconditionally
intercepted any call to a function named "length", even when the user
defined their own length() for a custom ADT. This produced invalid
WASM because the built-in assumes array (ptr, len) pair format.

The fix guards all 9 built-in handlers with a check against _known_fns
so they only activate when no user-defined function exists. This also
prevents the same class of bug for string_length, string_concat,
string_slice, char_code, parse_nat, parse_float64, to_string, and strip.

- examples/list_ops.vera now compiles and runs correctly (sum = 60)
- 3 new tests in TestBuiltinShadowing (1,347 total)
- Upgraded test_list_ops_example_file to verify runtime execution
- Version 0.0.58

Closes #154

Co-Authored-By: Claude <noreply@anthropic.invalid>
@aallan aallan merged commit 25a6518 into main Mar 3, 2026
10 checks passed
@aallan aallan deleted the feature/fix-list-ops-runtime branch March 3, 2026 21:44
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.

list_ops.vera fails at runtime: WASM compilation error in recursive generic ADT

1 participant