ASDAlexander77 / TypeScriptCompiler

TypeScript Compiler (by LLVM)
MIT License
618 stars 30 forks source link

dispose: is not called if returns earlier #77

Closed ASDAlexander77 closed 11 months ago

ASDAlexander77 commented 1 year ago
function loggy(id: string) {
    print(`Creating ${id}`);
    return {
        [Symbol.dispose]() {
            print(`Disposing ${id}`);
        }
    }
}

function func() {
    using a = loggy("a");
    using b = loggy("b");
    {
        using c = loggy("c");
        using d = loggy("d");
    }
    using e = loggy("e");
    return;
    // Unreachable.
    // Never created, never disposed.
    using f = loggy("f");
}

function main()
{
    func();
    print("done.");
}
ASDAlexander77 commented 11 months ago

fixed, code in the main branch