Skip to content

Lua: key a null class instance to 0 in wurstKeyOf - #1523

Merged
Frotty merged 1 commit into
masterfrom
lua-keyof-null-object
Oct 21, 2026
Merged

Frotty merged 1 commit into
masterfrom
lua-keyof-null-object

Conversation

@Frotty

@Frotty Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member

Problem

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 wurstKeyOf(none) gave nil: 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.lowerKeyOf now lowers a class-typed key to the value's cast to int. The Lua backend prints that as x or 0 (ExprTranslation.classToIndex), so a key and castTo int agree for every value, null included. Int keys are unchanged.

Tests

KeyedTableTests.nullClassInstanceKeysToZeroOnLuaToo checks that a null instance keys to 0 and that a live instance's key equals its castTo int and 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.

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.
@Frotty

Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T16:05:36.610825Z 51b6ac4 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit 51b6ac4 into master Oct 21, 2026
2 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@Frotty
Frotty deleted the lua-keyof-null-object branch November 25, 2026 08:54
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.

1 participant