|
| 1 | +// Compile-time regression test for issue #1630: `XdrValue.equals` must be |
| 2 | +// callable on union-typed values. The signature was once `equals(other: this)`, |
| 3 | +// and polymorphic `this` in parameter position intersects a union's arms — |
| 4 | +// discriminated arms with conflicting `type` properties reduce to `never`, so |
| 5 | +// no argument compiled (TS2345) on any of the SDK's union types even though |
| 6 | +// the runtime was correct. This file only has to typecheck; it never runs. |
| 7 | + |
| 8 | +import type { |
| 9 | + ScVal, |
| 10 | + ScValU32, |
| 11 | + TransactionEnvelope, |
| 12 | + LedgerEntry, |
| 13 | + LedgerEntryData, |
| 14 | + Memo, |
| 15 | + HostFunction, |
| 16 | + SorobanCredentials, |
| 17 | + InvokeContractArgs, |
| 18 | +} from "../../src/xdr/index.js"; |
| 19 | + |
| 20 | +declare const scValA: ScVal; |
| 21 | +declare const scValB: ScVal; |
| 22 | +declare const envelopeA: TransactionEnvelope; |
| 23 | +declare const envelopeB: TransactionEnvelope; |
| 24 | +declare const ledgerEntryDataA: LedgerEntryData; |
| 25 | +declare const ledgerEntryDataB: LedgerEntryData; |
| 26 | +declare const memoA: Memo; |
| 27 | +declare const memoB: Memo; |
| 28 | +declare const hostFunctionA: HostFunction; |
| 29 | +declare const hostFunctionB: HostFunction; |
| 30 | +declare const credentialsA: SorobanCredentials; |
| 31 | +declare const credentialsB: SorobanCredentials; |
| 32 | +declare const structA: InvokeContractArgs; |
| 33 | +declare const structB: InvokeContractArgs; |
| 34 | +declare const singleArm: ScValU32; |
| 35 | +declare const ledgerEntry: LedgerEntry; |
| 36 | + |
| 37 | +export const results: boolean[] = [ |
| 38 | + // Union receiver and union argument, for every union named in the issue. |
| 39 | + scValA.equals(scValB), |
| 40 | + envelopeA.equals(envelopeB), |
| 41 | + ledgerEntryDataA.equals(ledgerEntryDataB), |
| 42 | + memoA.equals(memoB), |
| 43 | + hostFunctionA.equals(hostFunctionB), |
| 44 | + credentialsA.equals(credentialsB), |
| 45 | + |
| 46 | + // Structs and single union arms keep working. |
| 47 | + structA.equals(structB), |
| 48 | + singleArm.equals(singleArm), |
| 49 | + |
| 50 | + // Single arm against the full union, both directions. |
| 51 | + singleArm.equals(scValA), |
| 52 | + scValA.equals(singleArm), |
| 53 | + |
| 54 | + // Cross-type comparison compiles and returns false at runtime. |
| 55 | + scValA.equals(memoA), |
| 56 | + |
| 57 | + // Union-typed property read — the real-world shape that surfaced the bug |
| 58 | + // (no `const` annotation to narrow the union back to one arm). |
| 59 | + ledgerEntry.data.equals(ledgerEntryDataA), |
| 60 | +]; |
0 commit comments