From db992237bd32cd0280aee680d1acd9ff01a547dd Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Mon, 29 Sep 2025 12:22:49 +0200 Subject: [PATCH] Fix bug in sigToIRDestructure A stray popNameContext() causes some trouble --- type-generation/src/astToIR.ts | 1 - type-generation/tests/a.test.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/type-generation/src/astToIR.ts b/type-generation/src/astToIR.ts index ced1193..834043a 100644 --- a/type-generation/src/astToIR.ts +++ b/type-generation/src/astToIR.ts @@ -932,7 +932,6 @@ export class Converter { const typeAliasDecl = tempFile.getTypeAliases()[0]; const dummyTypeNode = typeAliasDecl.getTypeNode()!; const res = this.typeToIR(dummyTypeNode, optional); - this.popNameContext(); // Don't remove the temp file, it causes crashes. TODO: Fix this? return res; }; diff --git a/type-generation/tests/a.test.ts b/type-generation/tests/a.test.ts index d670ad0..b61a417 100644 --- a/type-generation/tests/a.test.ts +++ b/type-generation/tests/a.test.ts @@ -1352,6 +1352,35 @@ describe("emit", () => { "def f(type_: str, /, *, type: str, payload: int | float) -> None: ...", ); }); + it("destructure getProp regression test", () => { + // At some point we had an extra popNameContext() in sigToIRDestructure() + // and this test failed. + const res = emitFile(` + type Q = {a: string} & { + f(options?: { + x: number | string; + }): void; + }; + declare function q(): Q; + `); + assert.strictEqual( + removeTypeIgnores(res.slice(1).join("\n\n")), + dedent(` + type Q = Q_iface + + def q() -> Q: ... + + class Q__Intersection0_iface(Protocol): + a: str = ... + + class Q__Intersection1_iface(Protocol): + def f(self, /, *, x: str | int | float) -> None: ... + + class Q_iface(Q__Intersection1_iface, Q__Intersection0_iface, Protocol): + pass + `).trim(), + ); + }); }); describe("Type literals", () => { it("simple", () => {