Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,17 @@ private static void lowerKeyOf(ImFunctionCall call, ImTranslator translator,
ImType type = call.getTypeArguments().size() == 1
? call.getTypeArguments().get(0).getType()
: value.attrTyp();
if (TypesHelper.isIntType(type) || type instanceof ImClassType) {
if (TypesHelper.isIntType(type)) {
value.setParent(null);
call.replaceBy(value);
return;
}
if (type instanceof ImClassType) {
// A null instance is nil on Lua; the cast to int keys it 0, as on Jass (an object's id otherwise).
value.setParent(null);
call.replaceBy(JassIm.ImCast(value, type, TypesHelper.imInt()));
return;
}
if (type instanceof ImTypeVarRef || type instanceof ImAnyType) {
throw new CompileError(call.attrTrace().attrErrorPos(),
JassKeyOfLowering.KEY_OF + " needs a concrete element type on Lua, but this call is made with "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ public void nullElementKeysToZeroAndDoesNotCollide() {
"endpackage"));
}

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

"package Test",
"import KeyedTable",
"class Marker",
"Marker none = null",
"init",
" let k = wurstKeyOf(none)",
" let some = new Marker",
" if k + 1 == 1 and k == none castTo int and wurstKeyOf(some) == some castTo int and wurstKeyOf(some) != 0",
" testSuccess()",
"endpackage"));
}

/**
* A key handed to a native the Lua lowering replaces: the replacement is built from a copy of
* the arguments, so the key in the copy has to be lowered as well.
Expand Down
Loading