Skip to content

Interpreter: an object read back from an old generic is that object - #1525

Merged
Frotty merged 3 commits into
masterfrom
fix-interpreter-old-generic-identity
Oct 21, 2026
Merged

Frotty merged 3 commits into
masterfrom
fix-interpreter-old-generic-identity

Conversation

@Frotty

@Frotty Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member

Problem

In compile-time code, let a = new A; let m = new HashMap<int, A>; m.put(7, a); return m.get(7) == a gave false, and that result was baked into the script on every target. At run time (Jass, and the interpreter on the transformed program) it is true.

An old generic's V is ImAnyType in the IM. HashMap.get ends in castTo any, and its caller uses the result as an A without a cast back. So before class elimination the interpreter holds the object's integer id where the program has the object. Member access, method calls, instanceof and destroy already accept that id (ProgramState.toObject). But == and != compared an ILconstObject by identity, so an object never equalled its own id.

A sibling turned up while testing: writing a field of such a value (m.get(7).x = 4) failed with "Ambiguous object id 1 in multiple id spaces". The write took the class only from the receiver's type, which is any.

Change

  • WurstOperator: == (also inside tuples) and != compare an object and an int by the object's id, in either order (sameValue), as both targets do, since an object is its id there. Reals and tuples are unchanged, and ILconst.equals/hashCode are untouched. The operator's other callers are constant folding (AttrConstantValue), which never sees objects, and the Jass interpreter, which runs translated code where objects are ints.
  • EvaluateExpr: a field write on a receiver of type any falls back to the class that declares the field, as the read already did (memberAccessClassType, shared).

Tests

Five tests in CompiletimeTests, each run at compile time and at run time. Each failed without the change:

  • the HashMap repro, and both operand orders with !=;
  • HashList;
  • nested containers (HashMap<int, HashMap<int, A>> and HashMap<int, LinkedList<A>>);
  • a field write and a method call on a value read back (this one fails with only the == fix).

Windows, bundled Lua 5.3, -PallBackends: CompiletimeTests 55, InterpreterTests 29, GenericsTests 81, NewFeatureTests 42, LuaBackendAuditTests 285, ClassesTests 128, DeterministicChecks 29, plus WurstOperatorTests 4, all passing. Not done: Linux and macOS.

Found by a defect audit of the 19-21 Oct merges.

Compile-time code which put an object into an old-generic container and
read it back got a different value: `m.get(7) == a` was false for a
HashMap<int, A>, and the false was baked into the script on every target,
while the same function answered true at run time.

An old generic erases its value to an int on the way in (castTo int) and
the value leaves the generic as `any` with no cast back, so before class
elimination the interpreter holds the object's id where the program has
the object. The class-value consumers (member access, method calls,
instanceof, destroy) already read such an id as its object through
ProgramState.toObject, but == and != compared an ILconstObject by
identity, so it never equalled its own id. An assignment to a field of
such a value failed as well: the lvalue member access took the class only
from the receiver's type, which is `any`, and looked the id up in every id
space, where the container's own id collided with it ("Ambiguous object
id").

== and != now compare an object and an int by the object's id, as both
targets do, and the lvalue member access falls back to the class which
declares the field, as the rvalue access already did. Tests cover HashMap
(both operand orders and !=), HashList, nested containers, and a field
write and method call on the value read back. LinkedList, which keeps the
object itself, a Table id cast back explicitly, and a null value already
behaved.
@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:34:23.972072Z aa80b5f 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 21, 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: 3b7918bab7

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

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 3b7918bab7

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

== compared the elements of tuples with the interpreter's object-or-id rule, but != fell back to raw equality of the whole tuple, so a tuple holding a value read back from an old generic was both == and != to the same tuple with the original object, and compile time could bake either answer. sameValue, which != negates, now compares tuple elements the same way, reals exactly as != does.
@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. Can't wait for the next one!

Reviewed commit: aa80b5f7bb

ℹ️ 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 d9dad72 into master Oct 21, 2026
2 checks passed
@Frotty
Frotty deleted the fix-interpreter-old-generic-identity 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