Skip to content

Commit b40b43c

Browse files
authored
Fix bug with using dispose when using disposable class (#1586)
1 parent 9e05143 commit b40b43c

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/lualib/Using.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function __TS__Using<TArgs extends Disposable[], TReturn>(
22
this: undefined,
3-
cb: (...args: TArgs) => TReturn,
3+
cb: (this: void, ...args: TArgs) => TReturn,
44
...args: TArgs
55
): TReturn {
66
let thrownError;

test/unit/using.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,27 @@ test("await using no extra diagnostics (#1571)", () => {
193193
}
194194
`.expectToHaveNoDiagnostics();
195195
});
196+
197+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1584
198+
test("works with disposable classes (#1584)", () => {
199+
util.testFunction`
200+
const log = [];
201+
202+
class Scoped {
203+
action(): void {
204+
log.push("action")
205+
}
206+
[Symbol.dispose]() {
207+
log.push("cleanup")
208+
}
209+
}
210+
211+
function TestScoped(): void {
212+
using s = new Scoped();
213+
s.action();
214+
}
215+
216+
TestScoped();
217+
return log;
218+
`.expectToEqual(["action", "cleanup"]);
219+
});

0 commit comments

Comments
 (0)