From 19aaf6ce88f1c8741574ea553c5d06112ceccaa2 Mon Sep 17 00:00:00 2001 From: Perryvw Date: Sat, 21 Sep 2024 18:04:20 +0200 Subject: [PATCH] Fix bug with using dispose when using disposable class --- src/lualib/Using.ts | 2 +- test/unit/using.spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/lualib/Using.ts b/src/lualib/Using.ts index c61d544eb..a720f6e60 100644 --- a/src/lualib/Using.ts +++ b/src/lualib/Using.ts @@ -1,6 +1,6 @@ export function __TS__Using( this: undefined, - cb: (...args: TArgs) => TReturn, + cb: (this: void, ...args: TArgs) => TReturn, ...args: TArgs ): TReturn { let thrownError; diff --git a/test/unit/using.spec.ts b/test/unit/using.spec.ts index 5182b8928..34b4fef67 100644 --- a/test/unit/using.spec.ts +++ b/test/unit/using.spec.ts @@ -193,3 +193,27 @@ test("await using no extra diagnostics (#1571)", () => { } `.expectToHaveNoDiagnostics(); }); + +// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1584 +test("works with disposable classes (#1584)", () => { + util.testFunction` + const log = []; + + class Scoped { + action(): void { + log.push("action") + } + [Symbol.dispose]() { + log.push("cleanup") + } + } + + function TestScoped(): void { + using s = new Scoped(); + s.action(); + } + + TestScoped(); + return log; + `.expectToEqual(["action", "cleanup"]); +});