Repository navigation
Lower a direct wurstKeyOf call on Lua - #1506
Merged
Merged
Conversation
On Lua the intrinsic kept its placeholder body, so wurstKeyOf(7) was 0 and every class instance shared key 0. LuaNativeLowering now lowers each call where it is made, from its type argument: an int or class instance is its own key, a handle becomes the GetHandleId call Lua makes for its type. Types without a stable integer key, and calls from erased generic code, are rejected with a diagnostic. The keyed tables are now lowered before the tree shake, so the Jass bodies they replace are dropped rather than lowered.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Oct 20, 2026
Lua: allocate an instantiation whose members need its type argument from its specialised class
#1512
Merged
Frotty
added a commit
that referenced
this pull request
Oct 21, 2026
The direct Lua lowering of wurstKeyOf (#1506) replaced the call by the value itself for a class or interface type. A null instance is nil on Lua, so its key was nil: arithmetic on it raised and no table can be indexed by it, where Jass and the interpreter answer 0. The call now lowers to the value's cast to int, which Lua prints as `x or 0`, so a key and `castTo int` agree for every value, null included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Lua a direct call of the
wurstKeyOfintrinsic answered its placeholder:wurstKeyOf(7)was 0 and every class instance shared key 0. Jass gives the intrinsic a body only after generic elimination (JassKeyOfLowering); Lua keeps generics erased, so the source bodyreturn 0survived and nothing lowered a direct call.KeyedTableTests.intKeyIsIdentityandclassInstanceKeyIsStablepassed on the interpreter and Jass and failed on Lua (BACKLOG.md).Change
LuaNativeLowering.transformlowers each direct call where it is made, from its type argument: anintor a class instance (an integer id on both targets) is its own key, a handle becomes the sameGetHandleIdcall Lua makes for a handle of that type (ImTranslator.handleIdNative). No helper call, allocation or guard.code, tuples) and a call from erased generic code are rejected with a diagnostic instead of answering 0 (AGENTS.md §3). The declaration check is shared with Jass (JassKeyOfLowering.isCheckedKeyOf).wurstKeyOf(key)has no concrete type on Lua, are dropped rather than lowered.Backend difference: a direct call from generic code compiles on Jass, which specialises it, and is a compile error on Lua, which erases it.
callFromGenericCodeIsRejectedOnLuaOnlypins this.Evidence
SaveInteger(ht, 0, wurstKeyOf(u), 5), which an early version left unlowered), rejected types and the generic-code rejection.wurstKeyOf(7): beforefunction wurstKeyOf(value4) return 0 endand a call; after the literal7, with nowurstKeyOfin the output.Tested on Windows with the bundled Lua 5.3; Linux runs in PR CI, macOS only on master. The change touches no filesystem or process code.