Repository navigation
Bind an inherited generic method's type parameters through the superclasses in the interpreter - #1524
Conversation
…lasses 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.
|
@codex review |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8064a24aa0
ℹ️ 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".
…tanceof-inherited
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Problem
A method a class inherits from a generic superclass (
class Sub extends G<int>) ran in the IM interpreter with G'sTunbound. The interpreter bound the type variables of the method's class by position from the receiver's own type arguments, andSubhas none. The interpreter runs compile-time code and@Testfunctions.instanceof: anew Box<T>()in such a method was recorded asBox<T>. Since Lua: tell the instantiations apart in an instanceof written in a closure #1515, itsinstanceof Box<int>threw "Cannot decide whether Box is a Box"; before that, it also counted as aBox<string>.Gread in such a method was keyed apart from the oneG<int>writes, so it read as uninitialised.Jass and Lua were right.
Change
ILInterpreter.runFunctakes the receiver's type as an instance of the method's class through the superclass chain (ProgramState.adaptToSuperclass, made public) before binding that class's type variables, asImAttrTypedoes for IM types since #1510. A receiver that does not reach the method's class keeps the old binding.Tests
Four tests in
GenericsTests, run in the interpreter, on Jass and on Lua. Each failed in the interpreter without the change:instanceofof an object made in a method inherited through one generic superclass (instanceofOfObjectMadeInInheritedGenericMethod) and through two;genericStaticReadInInheritedGenericMethod).Windows, bundled Lua 5.3,
-PallBackends: GenericsTests 85, GenericsWithTypeclassesTests 119, InterpreterTests 29, CompiletimeTests 50, LuaBackendAuditTests 285, ClassesTests 128, DeterministicChecks 29, GenericSpecialisationMatrixTests 384, GenericStoreGeneratedTests 48, all passing. Not done: Linux and macOS.Found by a defect audit of the 19-21 Oct merges.