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

Wrong behavior for loop with finally statement. #7211

Closed
dudubs opened this issue Apr 4, 2023 · 4 comments
Closed

Wrong behavior for loop with finally statement. #7211

dudubs opened this issue Apr 4, 2023 · 4 comments
Labels

Comments

@dudubs
Copy link

dudubs commented Apr 4, 2023

Describe the bug

When I run the code:
(async () => { let x = true; let c = 0; try { while (x) { x = false; await Promise.resolve(); } } finally { console.log("Count" + ++c); } })();
The expected output is:
Count1
What I got:
Count1 Count2.

From some reason the 'finally' called two times after end of loop.

link: https://play.swc.rs/?version=1.3.44&code=H4sIAAAAAAAAA02NTQrCMBCF94J3eHSVECjdS914Aa8QwlQDYwJJalskdze2xvpWMx%2FvB0LHxRkIif6M1%2FGAIqaEGT1SGOm0I1NQ9%2F1TWKobmO6WCWKWO8JaMGiOteEjPWmbcA3%2BYSO1gaLnJwn5c%2BTtyBis08x%2FE8a7YqaW%2FU00Fz%2B61EBBKVPDazTLUvYGez%2FLGdMAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D

thanks.

Input code

(async () => {
    let x = true;
    let c = 0;
    try {
      while (x) {
        x = false;
        await Promise.resolve();
      }
    } finally {
      console.log("Count" + ++c);
    }
  })();

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.44&code=H4sIAAAAAAAAA02NTQrCMBCF94J3eHSVECjdS914Aa8QwlQDYwJJalskdze2xvpWMx%2FvB0LHxRkIif6M1%2FGAIqaEGT1SGOm0I1NQ9%2F1TWKobmO6WCWKWO8JaMGiOteEjPWmbcA3%2BYSO1gaLnJwn5c%2BTtyBis08x%2FE8a7YqaW%2FU00Fz%2B61EBBKVPDazTLUvYGez%2FLGdMAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D

Expected behavior

To execute finally statement once after loop

Actual behavior

No response

Version

1.3.44

Additional context

No response

@dudubs dudubs added the C-bug label Apr 4, 2023
@dudubs dudubs changed the title Wrong behavior for loop and finally statement. Wrong behavior for loop with finally statement. Apr 4, 2023
@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2023
@kdy1
Copy link
Member

kdy1 commented Apr 5, 2023

Closing as dullicate

@kdy1
Copy link
Member

kdy1 commented Apr 5, 2023

There's an issue related to yield. (I'm on mobile now)

@kdy1
Copy link
Member

kdy1 commented Apr 5, 2023

Duplicate of #5913

@kdy1 kdy1 marked this as a duplicate of #5913 Apr 5, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented May 5, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators May 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants