Skip to content

fix(compiler): compare temporaries in ReadTemporaryExpr.isEquivalent - #71350

Closed
irontaek wants to merge 1 commit into
angular:mainfrom
irontaek:fix-read-temporary-equivalence
Closed

irontaek wants to merge 1 commit into
angular:mainfrom
irontaek:fix-read-temporary-equivalence

Conversation

@irontaek

Copy link
Copy Markdown
Contributor

PR Checklist

  • The commit message follows Angular's guidelines.
  • Tests for the changes have been added (see below).
  • Docs have been added / updated (not applicable: no API change).

PR Type

  • Bugfix

What is the current behavior?

ReadTemporaryExpr.isEquivalent in template/pipeline/ir/src/expression.ts ignores its argument:

override isEquivalent(): boolean {
  return this.xref === this.xref;
}

so a temporary read reports itself equivalent to any expression — a read of a different temporary, or an unrelated literal like o.NULL_EXPR. Every sibling IR expression checks the other operand (e instanceof X && e.xref === this.xref, etc.).

I haven't found a template that miscompiles because of this today; it breaks the isEquivalent contract that callers such as the trailing-NULL_EXPR trimming in instruction.ts rely on.

What is the new behavior?

isEquivalent returns true only for a ReadTemporaryExpr of the same temporary, matching the sibling expressions.

Tests

Added packages/compiler/test/template/pipeline/expression_spec.ts with three cases (same temporary, different temporary, unrelated expression). Before the fix the last two fail with Expected true to be false; after the fix all three pass.

Does this PR introduce a breaking change?

  • No

https://claude.ai/code/session_01W9Mk18mBNfkPfgg3hYweKq

ReadTemporaryExpr.isEquivalent ignored its argument and compared
this.xref with itself, so a temporary read was reported as equivalent
to any expression, including reads of other temporaries and literals
such as o.NULL_EXPR. Compare against the other read's xref like the
sibling IR expressions do.

Claude-Session: https://claude.ai/code/session_01W9Mk18mBNfkPfgg3hYweKq
@pullapprove
pullapprove Bot requested a review from crisbeto October 14, 2026 12:24
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Oct 14, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 14, 2026
@crisbeto

Copy link
Copy Markdown
Member

This is already covered in #71245.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Nov 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants