Files
scriptc/tests/diagnostics/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

13 lines
419 B
TypeScript

// One generic declaration held at two signatures compares unequal through
// `unknown` today (one closure per signature, one function object in
// JavaScript). Refuse it instead of answering silently wrong.
type Fn = (x: number) => number;
function ident<T>(x: T): T {
return x;
}
const a: Fn = ident;
const b: (x: string) => string = ident;
const ua = a as unknown;
const ub = b as unknown;
console.log(ua === ub);