Skip to content

Should reject using / await using in a switch case / default clause #62708

Closed

Description

@sapphi-red

🔎 Search Terms

explicit resource management, using, await using, switch, case clause, default clause

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&ts=6.0.0-dev.20251030#code/M4dwlgLgxgFgBACgLIEMIwHQCcUDsAmA9gLYICUZcA3gFBxxQrACmcADAFx31wCuwYXAHM4+AExs4AXmpwA2gGUAnsQBGhADYZ8YYAAdCLALrlqAXzhmA3N3qqszFAGsb3RizgBGLjzgoQKJB8AsKiYp7Ssooq6lo6+obMJpRUFta2cPaOLjRmNDTMAB4GWBDmNEA

💻 Code

switch (Math.random()) {
  case 0:
    using d20 = { [Symbol.dispose]() {} };
    break;

  case 1:
    await using d21 = { [Symbol.dispose]() {} };
    break;
}

export {}

🙁 Actual behavior

No error happens.

🙂 Expected behavior

The error is reported that using / await using cannot be used here.

Additional information about the issue

The spec was updated to disallow this (rbuckton/ecma262#14).
Related PRs in other projects:

Some tests needs to be updated. For example:

switch (Math.random()) {
case 0:
using d20 = { [Symbol.dispose]() {} };
break;
case 1:
using d21 = { [Symbol.dispose]() {} };
break;
}
if (true)
switch (0) {
case 0:
using d22 = { [Symbol.dispose]() {} };
break;
}

Activity

  1. RyanCavanaugh commented on Nov 5, 2025

    @RyanCavanaugh
  2. added 2 commits that reference this issue on Nov 7, 2025
    572ddf1
    b40893d
  3. locked as resolved and limited conversation to collaborators on May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: ParserThe parser didn't handle the syntax correctlyHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions