Skip to content

Convert a unary expression handed to an old generic once on Lua - #1536

Merged
Frotty merged 2 commits into
masterfrom
lua-unary-old-generic-arg
Oct 22, 2026
Merged

Frotty merged 2 commits into
masterfrom
lua-unary-old-generic-arg

Conversation

@Frotty

@Frotty Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member

On Lua, a unary expression whose value goes to an old generic <T> was converted to the erased index twice. This covers an argument, a closure's result or a block's result: -2.5, not b or -(c ? 1. : 2.). The operand took the generic's conversion, and then so did the result. So id<real>(-2.5) printed as realToIndex(-(realToIndex(2.5))) and read back as -2500, and list.add(-2.) stored -2000. Jass and the interpreter were right. Jass prints realToIndex( - 2.).

Cause. In imtranslation/ExprTranslation.translateWithExpectedType, the ExprUnary case passed the expected type to its operand. That path only runs for Lua.

Fix. The operand now takes the operator's own type, from its own expected type. Only the result converts to what the context expects.

Test. LuaBackendAuditTests.unaryExpressionPassedToAnOldGenericIsConvertedOnce runs on Jass and Lua. It covers:

  • an argument and not;
  • a closure result;
  • a vararg add and map;
  • a negated if-else;
  • a negated erased field (-b.v), which master already handled and an earlier version of this fix broke.

The test fails with master's translator ("Succeed function not called") and passes with the fix. LuaBackendAuditTests, LuaTranslationTests, GenericsTests, ClosureTests, LuaTypecastingTests and ExpressionTests pass. Only Windows was run.

An argument, closure result or block result such as -2.5 for an old generic
parameter was converted to the erased index twice on Lua: the operand took the
generic's conversion as well as the result, so realToIndex(-(realToIndex(2.5)))
read back as -2500, and -(c ? 1. : 2.) as -1000. The operand now takes the
operator's own type and only the result converts.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-22T09:05:11.407683Z 61a7261 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 commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: f2e0ffd274

ℹ️ 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".

…erics

The regression test also checks the emitted Lua: no unary operand converts to the erased index,
and the negated real and boolean convert once. A new-generic counterpart hands the same unary
expressions to a <T:> function, closure and class and checks that they go through no index.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 61a72618e4

ℹ️ 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".

@Frotty
Frotty merged commit 5f90acd into master Oct 22, 2026
2 checks passed
@Frotty
Frotty deleted the lua-unary-old-generic-arg 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