Skip to content

fix(vm): encode Elixir nil to Lua nil instead of the string "nil"#375

Open
smn wants to merge 1 commit into
tv-labs:mainfrom
smn:asymmetric-nil-handling
Open

fix(vm): encode Elixir nil to Lua nil instead of the string "nil"#375
smn wants to merge 1 commit into
tv-labs:mainfrom
smn:asymmetric-nil-handling

Conversation

@smn

@smn smn commented Jun 20, 2026

Copy link
Copy Markdown

Fixes #374

full disclosure: Claude helped here

`Lua.encode!/2` matched `nil` in its atom-encoding head (`nil` is an atom
that is not a boolean) and converted it to the string `"nil"`. Because all
Lua strings are truthy, encoded `nil` silently inverted `if not value then`
checks and broke `return nil, "reason"` error-tuple patterns, and the
round trip `decode!(encode!(nil))` was lossy.

Add a dedicated `encode!/2` head that maps Elixir `nil` to Lua `nil`,
matching `decode!/2` and the existing handling of `nil` inside tables and
function result lists.

Fixes tv-labs#374
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.

Lua.encode!/2 encodes Elixir nil as the Lua string "nil" instead of Lua nil (asymmetric with decode)

2 participants