You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a really interesting one! It actually has nothing to do with
macrodebug, other than the fact that the bug happens during
compilation to lua, so macrodebug isn't affected.
What happens is that the parser puts a keys field in a metatable on
every key/value table literal it reads. This allows the table to be
reconstructed exactly as it was originally in the input; even though
key/value tables are un-ordered in their representation, we can emit
them with their keys in the original order.
The problem is that a macro can modify a table in a way that doesn't
actually change the separate keys table. When the compiler emits a
Lua table, currently it only pays attention to keys and if it
disagrees with the actual value of the table itself, the keys table
wins.
The correct behavior is to use keys only for ordering: we must ignore
entries which don't exist in the table, and we must ensure that
legitimate keys which aren't found in keys are still emitted in the Lua.
Anyway the best solution here of course is to not use a macro; this
code is much better suited for a function. But it is a legitimate bug in
the compiler, so I'll put together a fix for it. In the mean time if you
can't replace it with a function without breaking compatibility, you can
work around the bug by avoiding the use of :into and copying fields
manually for the time being.
Thanks for finding this.
technomancy
changed the title
Compilation result differs from macrodebug result
Table literals modified by macros don't get all their fields emitted
May 3, 2022
Environment
How reproduce the issue
1. Create a new file containing the following content:
2. Execute the following command:
Expected result
The compilation result must be equals to the
macrodebug
result:Current result
The compilation result differs from the
macrodebug
result:The text was updated successfully, but these errors were encountered: