Repository navigation
Keep the toIndex of a generic argument on Lua - #1502
Merged
Merged
Conversation
On Lua the expected type of a generic argument came from the selected overload, normalised, which dropped the bound type parameter and with it the toIndex conversion. A value read from an old generic and passed straight back into one then kept its fromIndex alone: c.set(c.get()) on a Cell<bla> passed the tuple to a one-parameter function. Use the raw parameter type, so the two conversions cancel as they do on Jass.
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
Frotty
added a commit
that referenced
this pull request
Oct 21, 2026
#1502 stopped normalising attrExpectedTypAfterOverloading so that the Lua translation of a generic argument keeps its bound type parameter and with it the toIndex conversion. The closure checks and the closure translation read the same attribute, and a bound type parameter is neither a class nor an interface type, so a closure passed to a generic parameter was rejected: listeners.add(() -> ...) on an ArrayList<Listener> failed with "Closures can only be used when a interface or class type is given, but at this position a Listener is expected", for old and new generics, vararg or not. The attribute is normalised again, as before #1502; the translation asks for the raw parameter type by its own method.
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.
Problem
On Lua, a value read from an old generic (
<T>) and passed straight back into one lost itstoIndexconversion while keeping itsfromIndex:Jass cancels the pair and emits
call dispatch_Cell_Cell_set(c, dispatch_Cell_Cell_get(c)). Lua emittedz, y = blaFromIndex(__wurst_ensureInt(Cell_Cell_get(c)))and thenCell_Cell_set(receiver, z, y): the tuple's two components went to a one-parameter function with noblaToIndex, so the wrong value was stored (with-inline -localOptimizations, a never-assigned local, i.e. nil).Cause
Since #1280, on Lua the expected type of a generic argument is the selected overload's parameter type (
AttrExprExpectedType.afterOverloading). That method normalised the type, which turns a bound type parameter into its base type, sowrapTranslationsaw an expectedblainstead of a boundTwithblaToIndex. Only thefromIndexside applied.Fix
afterOverloadingreturns the raw parameter type (and the raw expected type in its fallback), so both conversions are seen and cancel as on Jass. A parameter which is not a bound type parameter is unchanged, becausenormalize()only differs for bound type parameters.Evidence
GenericsTests.nestedOldGenericConversionsCanceland...CancelOptimized(-inline -localOptimizations) run on the interpreter, Jass and Lua. The conversions are deliberately asymmetric (blaToIndexmultiplies by 10) so a missing one shows. Both failed on Lua before the fix ("Succeed function not called") and pass after.GenericsTests.implicitConversions2no longer opts out of Lua (testLua(true).luaOnly(false)).GenericsTests(73),GenericsWithTypeclassesTests(115),LuaBackendAuditTests(242),LuaTranslationTests(144).Cell_Cell_set(c, Cell_Cell_get(c)), matching Jass.Platforms
Ran on Windows only. The change is a type lookup in the translation with no host-dependent code, but Linux and macOS are left to CI.