-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
built-in iterators should be disposable #59633
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/awaitUsingDeclarationsWithAsyncIteratorObject.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
awaitUsingDeclarationsWithAsyncIteratorObject.ts(11,23): error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
|
||
|
||
==== awaitUsingDeclarationsWithAsyncIteratorObject.ts (1 errors) ==== | ||
declare const ai: AsyncIterator<string, undefined>; | ||
declare const aio: AsyncIteratorObject<string, undefined, unknown>; | ||
declare const ag: AsyncGenerator<string, void>; | ||
|
||
async function f() { | ||
// should pass | ||
await using it0 = aio; | ||
await using it1 = ag; | ||
|
||
// should fail | ||
await using it2 = ai; | ||
~~ | ||
!!! error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
tests/baselines/reference/awaitUsingDeclarationsWithAsyncIteratorObject.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsWithAsyncIteratorObject.ts] //// | ||
|
||
=== awaitUsingDeclarationsWithAsyncIteratorObject.ts === | ||
declare const ai: AsyncIterator<string, undefined>; | ||
>ai : Symbol(ai, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 0, 13)) | ||
>AsyncIterator : Symbol(AsyncIterator, Decl(lib.es2018.asynciterable.d.ts, --, --)) | ||
|
||
declare const aio: AsyncIteratorObject<string, undefined, unknown>; | ||
>aio : Symbol(aio, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 1, 13)) | ||
>AsyncIteratorObject : Symbol(AsyncIteratorObject, Decl(lib.es2018.asynciterable.d.ts, --, --), Decl(lib.esnext.disposable.d.ts, --, --)) | ||
|
||
declare const ag: AsyncGenerator<string, void>; | ||
>ag : Symbol(ag, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 2, 13)) | ||
>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) | ||
|
||
async function f() { | ||
>f : Symbol(f, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 2, 47)) | ||
|
||
// should pass | ||
await using it0 = aio; | ||
>it0 : Symbol(it0, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 6, 15)) | ||
>aio : Symbol(aio, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 1, 13)) | ||
|
||
await using it1 = ag; | ||
>it1 : Symbol(it1, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 7, 15)) | ||
>ag : Symbol(ag, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 2, 13)) | ||
|
||
// should fail | ||
await using it2 = ai; | ||
>it2 : Symbol(it2, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 10, 15)) | ||
>ai : Symbol(ai, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 0, 13)) | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/awaitUsingDeclarationsWithAsyncIteratorObject.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsWithAsyncIteratorObject.ts] //// | ||
|
||
=== awaitUsingDeclarationsWithAsyncIteratorObject.ts === | ||
declare const ai: AsyncIterator<string, undefined>; | ||
>ai : AsyncIterator<string, undefined, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
declare const aio: AsyncIteratorObject<string, undefined, unknown>; | ||
>aio : AsyncIteratorObject<string, undefined, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
declare const ag: AsyncGenerator<string, void>; | ||
>ag : AsyncGenerator<string, void, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
async function f() { | ||
>f : () => Promise<void> | ||
> : ^^^^^^^^^^^^^^^^^^^ | ||
|
||
// should pass | ||
await using it0 = aio; | ||
>it0 : AsyncIteratorObject<string, undefined, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>aio : AsyncIteratorObject<string, undefined, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
await using it1 = ag; | ||
>it1 : AsyncGenerator<string, void, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>ag : AsyncGenerator<string, void, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
// should fail | ||
await using it2 = ai; | ||
>it2 : AsyncIterator<string, undefined, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>ai : AsyncIterator<string, undefined, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/awaitUsingDeclarationsWithIteratorObject.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
awaitUsingDeclarationsWithIteratorObject.ts(20,23): error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
|
||
|
||
==== awaitUsingDeclarationsWithIteratorObject.ts (1 errors) ==== | ||
declare const i: Iterator<string, undefined>; | ||
declare const io: IteratorObject<string, undefined, unknown>; | ||
declare const g: Generator<string, void>; | ||
|
||
class MyIterator extends Iterator<string> { | ||
next() { return { done: true, value: undefined }; } | ||
} | ||
|
||
async function f() { | ||
// should pass | ||
await using it0 = io; | ||
await using it1 = g; | ||
await using it2 = Iterator.from(i) | ||
await using it3 = new MyIterator(); | ||
await using it4 = [].values(); | ||
await using it5 = new Map<string, string>().entries(); | ||
await using it6 = new Set<string>().keys(); | ||
|
||
// should fail | ||
await using it7 = i; | ||
~ | ||
!!! error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these tests of existing functionality? I don't see how changing the type of [Async]IteratorObject would change its runtime behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was in the wrong test suite. I merely moved while adding other tests.