Skip to content

fix(vm): raise a clear error when encoding a decoded table - #421

Open
SAY-5 wants to merge 2 commits into
tv-labs:mainfrom
SAY-5:fix-encode-decoded-table
Open

SAY-5 wants to merge 2 commits into
tv-labs:mainfrom
SAY-5:fix-encode-decoded-table

Conversation

@SAY-5

@SAY-5 SAY-5 commented Aug 23, 2026

Copy link
Copy Markdown

Closes #408.

Value.encode/3 had no clause for a list of {key, value} pairs, which is exactly the shape decode/2 produces for a table. Passing a decoded table straight back into set!/3 fell into the positional-list branch and crashed with a bare FunctionClauseError (each pair is a 2-tuple matching no encode clause).

This adds a branch that refuses that shape with a clear message pointing at Map.new/1, mirroring the existing struct and cyclic-tref refusals. Behavior for keyword lists and plain sequences is unchanged.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Comment thread lib/lua/vm/value.ex Outdated
Comment on lines +298 to +301
"cannot encode a list of {key, value} pairs into a Lua value. This is the " <>
"shape `decode/2` produces for a table, and it does not round-trip back " <>
"into the VM. Convert it to a map first (e.g. `Map.new/1`), which encodes " <>
"as a Lua table."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use a heredoc here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched it to a heredoc in 508cd5c, the rendered message is unchanged.

@davydog187 davydog187 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! just one nitpick on the error message string construction

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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.

Decoded tables cannot round-trip through set!/encode! (FunctionClauseError on {key, value} pairs)

2 participants