Files
scriptc/tests/corpus/generic-identity-unknown.ts
T
Malte UblandClaude Opus 5.5 bb0e0a79d5 Compare generic declarations by identity across pinned signatures
An unpinned generic declaration compared with `===`/`!==` takes its
signature from the other operand (`held === ident`), which clears the pi
`agent-session.ts:590` shape.

That pin alone would answer `false` where JavaScript answers `true` when
the program also holds the declaration at another signature, so a
whole-program check refuses the comparison instead. It covers the direct
form and values compared through `unknown` (the g5 silent divergence:
two instances of one declaration compared unequal), resolving dynamic
operands' provenance only when some declaration is held at more than one
signature.

- generic-functions: `identityComparisonPin` and
  `checkGenericIdentityPins` (runs once at the end of lowering, when every
  value instance is known); `GenericFnInfo.valueInstances` records the
  instances value references produced.
- Corpus: `generic-identity-pin.ts`, `generic-identity-unknown.ts`.
- Diagnostics: `generic-identity-multiple-pins.ts`,
  `generic-identity-unknown.ts`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 09:41:25 -07:00

12 lines
429 B
TypeScript

// A generic declaration held at one signature compares equal to itself
// through `unknown`, and further calls at other signatures (which do not
// hold the declaration as a second function object) stay compilable.
type Fn = (x: number) => number;
function ident<T>(x: T): T {
return x;
}
const f: Fn = ident;
const u: unknown = f;
console.log(u === f, u !== f, f(4));
console.log(ident<number>(5), ident("s").toUpperCase());