Skip to content

Commit 3506061

Browse files
authored
Fix bug in sigToIRDestructure (#73)
A stray popNameContext() causes some trouble
1 parent c245ede commit 3506061

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

type-generation/src/astToIR.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,6 @@ export class Converter {
932932
const typeAliasDecl = tempFile.getTypeAliases()[0];
933933
const dummyTypeNode = typeAliasDecl.getTypeNode()!;
934934
const res = this.typeToIR(dummyTypeNode, optional);
935-
this.popNameContext();
936935
// Don't remove the temp file, it causes crashes. TODO: Fix this?
937936
return res;
938937
};

type-generation/tests/a.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,35 @@ describe("emit", () => {
13521352
"def f(type_: str, /, *, type: str, payload: int | float) -> None: ...",
13531353
);
13541354
});
1355+
it("destructure getProp regression test", () => {
1356+
// At some point we had an extra popNameContext() in sigToIRDestructure()
1357+
// and this test failed.
1358+
const res = emitFile(`
1359+
type Q = {a: string} & {
1360+
f(options?: {
1361+
x: number | string;
1362+
}): void;
1363+
};
1364+
declare function q(): Q;
1365+
`);
1366+
assert.strictEqual(
1367+
removeTypeIgnores(res.slice(1).join("\n\n")),
1368+
dedent(`
1369+
type Q = Q_iface
1370+
1371+
def q() -> Q: ...
1372+
1373+
class Q__Intersection0_iface(Protocol):
1374+
a: str = ...
1375+
1376+
class Q__Intersection1_iface(Protocol):
1377+
def f(self, /, *, x: str | int | float) -> None: ...
1378+
1379+
class Q_iface(Q__Intersection1_iface, Q__Intersection0_iface, Protocol):
1380+
pass
1381+
`).trim(),
1382+
);
1383+
});
13551384
});
13561385
describe("Type literals", () => {
13571386
it("simple", () => {

0 commit comments

Comments
 (0)