Repository navigation
Type a method call on an inherited generic method with the superclass's type arguments - #1510
Merged
Merged
Conversation
…ments
The IM type of a method call substituted only the type arguments of the
receiver's own class. A method which the receiver's class inherits from a
generic superclass (class Sub extends G<pa>) therefore had G's type variable
T as its type. The translation keeps such a call's result in a temporary of
that type (g.r().x, and the branches of a conditional expression), so a local
of type T was left in a function where T is not in scope: tuple elimination
failed on the selection ("//// Before") on Jass and Lua, and the conditional
failed Jass translation ("Type variable T not eliminated").
ImAttrType now follows the receiver's type through its superclasses to the
method's class and substitutes that class's type arguments.
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
Lua: allocate an instantiation whose members need its type argument from its specialised class
#1512
Merged
This was referenced Oct 21, 2026
Bind an inherited generic method's type parameters through the superclasses in the interpreter
#1524
Merged
Frotty
added a commit
that referenced
this pull request
Oct 21, 2026
…lasses in the interpreter (#1524) * Bind an inherited generic method's type parameters through the superclasses in the interpreter A method a class inherits from a generic superclass (class Sub extends G<int>) ran in the IM interpreter with G's T unbound. The interpreter bound the type variables of the method's class positionally from the receiver's own type arguments, so a Sub, which has none, left T open. A new Box<T>() in such a method was then recorded as Box<T>: since #1515 its instanceof threw "Cannot decide whether Box<T> is a Box<integer>", and before that it took the object for a Box<string> too. A static of G read in such a method was keyed apart from the one G<int> writes, so it read as uninitialised. Jass and Lua were right, because their specialisation follows the superclass edge, as ImAttrType does for IM types since #1510. The interpreter now takes the receiver's type as an instance of the method's class through the superclass chain (ProgramState.adaptToSuperclass) before it binds that class's type variables. Adds tests for an instanceof of an object made in an inherited method, through one and two generic superclasses and in a default method of a generic interface, and for a static per instantiation read in an inherited method, on Jass, Lua and the interpreter. * Test an inherited method of an old generic class too The interpreter's binding of an inherited method's type parameters through the superclasses serves both generic systems. An old generic's parameter is erased, so cover a value returned by a method inherited through one and two old-generic superclasses, in the interpreter and on both targets.
Frotty
added a commit
that referenced
this pull request
Oct 21, 2026
…ents (#1526) The IM type of a member access substituted only the type arguments of the receiver's own class. A field which the receiver's class inherits from a generic superclass (class Sub extends G<int>, G declaring T v) therefore had G's type variable T as its type. The translation keeps the branches of a conditional expression in a temporary of the first branch's type, so b ? s.v : 5 left a local of type T in a function where T is not in scope, and Jass translation failed with "Type variable T not eliminated". Lua and the interpreter passed, and a tuple argument (Sub extends G<pa>) passed. ImAttrType.getType(ImMemberAccess) now follows the receiver's type through its superclasses to the class declaring the field and substitutes that class's type arguments, as getType(ImMethodCall) does since #1510. This covers the implicit receiver in a subclass method, a field two generic superclasses up, and a generic subclass passing its own argument to a later type parameter of the superclass.
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.
EliminateTuplescrashed ("//// Before ...") on a field of the tuple which a subclass's inherited generic method returns, on both Jass and Lua; a conditional over such a call failed Jass translation with "Type variable T not eliminated":Found by the bounded-exhaustive matrix of #1505 (tag
lua-tuple-elimination-crash).Cause
ImAttrType.getType(ImMethodCall)filled in only the type arguments of the receiver's own class. Forclass Sub extends G<pa>the callg.r()therefore had typeT(G's type variable), andExprTranslationbuilt its temporaries from that type (temp_tupleforg.r().x,cond_resultforb ? g.r() : ...), leaving a local of typeTthatEliminateTuplesand the Jass translation could not handle.Change
The IM type of a method call now follows the receiver's class up its superclass edges to the method's class and substitutes that class's type arguments. A receiver type without its class's type arguments keeps the previous behaviour.
Evidence
im2.jdebug dump.The matrix's closure variant of this tag (
STATIC_CLOSURE_wCLOSURE_rDESTROY_TUPLEx2_opt) still fails: it is a different defect, a specialised closure writing the erased static (lua-static-erased), and stays listed.Tested on Windows with the bundled Lua 5.3; Linux runs in PR CI, macOS only on master.