Files
scriptc/packages/compiler/test/class-protocol-boundaries.test.ts
T
Chris Tate 4060ea51d4 Expect generic protocol dispatch to compile
A class behind an interface whose method is generic now dispatches to
the method's erased instance, so the boundary test compiles the program
instead of expecting the old refusal.

Fixes #905
Co-authored-by: Konstantin Mikheev <8560582+konmik@users.noreply.github.com>
2026-10-17 19:11:33 -05:00

33 lines
1.1 KiB
TypeScript

import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, test } from "vitest";
import { compile } from "../src/index.js";
test("generic protocol dispatch without a concrete body calls the erased method", async () => {
const directory = mkdtempSync(join(tmpdir(), "scriptc-protocol-boundary-"));
try {
const entry = join(directory, "main.ts");
writeFileSync(
entry,
`interface Live { value(): number; identity<T>(value: T): T; }
class Value implements Live {
value(): number { return 1; }
identity<T>(value: T): T { return value; }
}
function read(value: Live): number { return value.identity(3); }
console.log(read(new Value()));`,
);
const result = await compile(entry, {
outDir: directory,
outPath: join(directory, "program.ir"),
outputKind: "ir",
});
if (!result.ok)
throw new Error(result.diagnostics.map((d) => `${d.code}: ${d.message}`).join("\n"));
expect(result.ok).toBe(true);
} finally {
rmSync(directory, { recursive: true, force: true });
}
});