Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using keyword generate various errors #22392

Closed
JOTSR opened this issue Feb 12, 2024 · 4 comments
Closed

using keyword generate various errors #22392

JOTSR opened this issue Feb 12, 2024 · 4 comments
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling) upstream Changes in upstream are required to solve these issues

Comments

@JOTSR
Copy link
Contributor

JOTSR commented Feb 12, 2024

Version: Deno 1.40.4

Summary

Declarations of an instance of a local Disposable class generate the following errors:

  • LSP is broken (code completions does not work anymore)
  • Runtime throws error when calling Symbol.dispose/Symbol.asyncDispose

Calling Symbol.dispose result in error if there is more than one scope with using or when there is using in global scope with local class.

Examples

With Symbol.dispose

export class Disposable {
    [Symbol.dispose]() {
        console.log('dispose')
    }

}

using _f = await Deno.open('./demo.txt')

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
ok

With Symbol.dispose and global using

export class Disposable {
    [Symbol.dispose]() {
        console.log('dispose')
    }

}

using _disposable = new Disposable()

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
error: Uncaught (in promise) TypeError: Property [Symbol.dispose] is not a function.
Warning Couldn't format source line: Line 52 is out of bounds (source may have changed at runtime)
    at _using (file:///.../src/example.ts:52:11)
    at file:///.../src/example.ts:9:1

With Symbol.dispose and scoped using

export class Disposable {
    [Symbol.dispose]() {
        console.log('dispose')
    }

}

{
    using _disposable = new Disposable()
}

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
dispose
ok

With Symbol.dispose scoped using and Deno using

export class Disposable {
    [Symbol.dispose]() {
        console.log('dispose')
    }

}

using _f = await Deno.open('./demo.txt')

{
    using _disposable = new Disposable()
}

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
error: Uncaught (in promise) TypeError: Property [Symbol.dispose] is not a function.
Warning Couldn't format source line: Line 52 is out of bounds (source may have changed at runtime)
    at _using (file:///.../src/example.ts:52:11)
    at file:///.../src/example.ts:11:5
    at eventLoopTick (ext:core/01_core.js:65:7)

With Symbol.dispose scoped using and scoped Deno using

export class Disposable {
    [Symbol.dispose]() {
        console.log('dispose')
    }

}

{
    using _f = await Deno.open('./demo.txt')
    using _disposable = new Disposable()
}

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
dispose
ok

With Symbol.AsyncDispose scoped using and scoped Deno using

export class Disposable {
    [Symbol.asyncDispose]() {
        console.log('dispose')
    }

}

{
    using _f = await Deno.open('./demo.txt')
    await using _asyncDisposable = new AsyncDisposable()
}

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
dispose
ok

With Symbol.AsyncDispose scoped using and Deno using

export class Disposable {
    [Symbol.asyncDispose]() {
        console.log('dispose')
    }

}

using _f = await Deno.open('./demo.txt')

{
    await using _asyncDisposable = new AsyncDisposable()
}

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
dispose
ok

With Symbol.AsyncDispose scoped using and scoped Deno using

export class Disposable {
    async [Symbol.asyncDispose]() {
        console.log('dispose')
    }

}

{
    using _f = await Deno.open('./demo.txt')
    await using _asyncDisposable = new AsyncDisposable()
}

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
dispose
ok

With Symbol.AsyncDispose scoped using and Deno using

export class Disposable {
    async [Symbol.asyncDispose]() {
        console.log('dispose')
    }

}

using _f = await Deno.open('./demo.txt')

{
    await using _asyncDisposable = new AsyncDisposable()
}

console.log('ok')
$ deno run --allow-read=. ./src/example.ts
error: Uncaught (in promise) TypeError: Property [Symbol.dispose] is not a function.
Warning Couldn't format source line: Line 52 is out of bounds (source may have changed at runtime)
    at _using (file:///.../src/example.ts:52:11)
    at file:///.../src/example.ts:11:5
    at eventLoopTick (ext:core/01_core.js:65:7)
@dsherret
Copy link
Member

This is a regression. I opened swc-project/swc#8629

@dsherret dsherret added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Feb 12, 2024
@bombillazo
Copy link

Hey, I tried using using as well recently but we get a TypeError: Property [Symbol.dispose] is not a function. error, we are only defining asyncDispose since it is a connection closing function.

@BlowaterNostr
Copy link

BlowaterNostr commented Jun 1, 2024

Same problem here. It fails in Linux (GitHub Action)

deno 1.44.0 (release, x86_64-unknown-linux-gnu)
v8 12.6.228.3
typescript 5.4.5

using https://github.com/denoland/setup-deno

@lucacasonato
Copy link
Member

All of these examples are working for me in Deno 1.44.1.

@BlowaterNostr please share what issue you are running into if it is not fixed.

@lucacasonato lucacasonato added the upstream Changes in upstream are required to solve these issues label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling) upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

5 participants