Repository navigation
Lua: key a null class instance to 0 in wurstKeyOf - #1523
Conversation
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.
|
@codex review |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 51b6ac4def
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /** A null class instance keys to 0 on every target, as its castTo int does, and as a null unit does above. */ | ||
| @Test | ||
| public void nullClassInstanceKeysToZeroOnLuaToo() { | ||
| test().testLua(true).luaOnly(false).executeProg(true).withStdLib().lines(withKeyedTable( |
There was a problem hiding this comment.
Add a generated-Lua assertion for the null-class key
This is a Lua backend parity fix, but the new regression only executes the program and never inspects the generated Lua to verify that the null class value lowers to the intended (none or 0) shape without a helper or boxing conversion. Add a compiledLua assertion covering the new class-to-int lowering, as required for backend parity fixes.
AGENTS.md reference: AGENTS.md:L362-L365
Useful? React with 👍 / 👎.
Problem
The direct Lua lowering of
wurstKeyOf(#1506) replaced the call by the value itself for a class or interface type. A null instance isnilon Lua, sowurstKeyOf(none)gavenil: arithmetic on the key raised "attempt to perform arithmetic on a nil value", and a Lua table cannot be indexed by it. The interpreter and Jass answer 0. This is a regression from #1506; before it, Lua answered a placeholder 0 for every key.Change
LuaNativeLowering.lowerKeyOfnow lowers a class-typed key to the value's cast to int. The Lua backend prints that asx or 0(ExprTranslation.classToIndex), so a key andcastTo intagree for every value, null included. Int keys are unchanged.Tests
KeyedTableTests.nullClassInstanceKeysToZeroOnLuaToochecks that a null instance keys to 0 and that a live instance's key equals itscastTo intand is not 0. It runs in the interpreter, on Jass and on Lua, and failed on master on Lua.Windows, bundled Lua 5.3,
-PallBackends: KeyedTableTests 18, LuaKeyedMapTests 39, LuaTranslationTests 149, LuaBackendAuditTests 285, FastHashMapTests 15, GenericsTests 81, DeterministicChecks 29, all passing. Not done: Linux and macOS (PR CI covers Ubuntu only).Found by a defect audit of the 19-21 Oct merges.