Skip to content

Bind an inherited generic method's type parameters through the superclasses in the interpreter - #1524

Merged
Frotty merged 3 commits into
masterfrom
fix-interpreter-instanceof-inherited
Oct 21, 2026
Merged

Frotty merged 3 commits into
masterfrom
fix-interpreter-instanceof-inherited

Conversation

@Frotty

@Frotty Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member

Problem

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 by position from the receiver's own type arguments, and Sub has none. The interpreter runs compile-time code and @Test functions.

Jass and Lua were right.

Change

ILInterpreter.runFunc takes 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, as ImAttrType does 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:

  • instanceof of an object made in a method inherited through one generic superclass (instanceofOfObjectMadeInInheritedGenericMethod) and through two;
  • the same in a default method of a generic interface;
  • a static per instantiation read in an inherited method (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.

…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.
@Frotty

Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T16:20:42.158091Z 6597420 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.

@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: 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".

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

Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 6597420d5e

ℹ️ 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 1911256 into master Oct 21, 2026
2 checks passed
@Frotty
Frotty deleted the fix-interpreter-instanceof-inherited 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