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

Bug: Infinite loop adding | boolean to a union typed parameter #1284

Closed
micrology opened this issue Aug 21, 2023 · 5 comments · Fixed by #1481
Closed

Bug: Infinite loop adding | boolean to a union typed parameter #1284

micrology opened this issue Aug 21, 2023 · 5 comments · Fixed by #1481
Labels
fixer: no implicit any status: accepting prs Please, send a pull request to resolve this! 🙏 type: bug Something isn't working :( 🐛

Comments

@micrology
Copy link

🐛 Bug Report

  • TypeStat version: current
  • TypeScript version: N/A
  • Node version: v20.3.1

Actual Behavior

It looks like TypeStat has ended up in an infinite loop.

Expected Behavior

File processed

Reproduction

Source javascript file is at https://github.com/micrology/prsm/blob/master/js/prsm.js

typestat.json:

cat typestat.json
[
    {
        "files": {
            "renameExtensions": true
        },
        "fixes": {
            "importExtensions": true
        },
        "include": [
            "src/**/*.{js,jsx}"
        ],
        "project": "./tsconfig.json"
    },
    {
        "fixes": {
            "incompleteTypes": true,
            "missingProperties": true,
            "noImplicitAny": true
        },
        "cleanups": {
            "suppressTypeErrors": true
        },
        "include": [
            "src/**/*.{ts,tsx}"
        ],
        "project": "./tsconfig.json"
    }
]%                        

Console log:

npx typestat --config typestat.json
🚀 Welcome to TypeStat!
⚠️ TypeStat is still very early stage and experimental. ⚠️
While it will improve your code, it will likely add syntax and type errors.
Use TypeStat as a starting point before you manually fix and verify any changes.
TypeStat will run through the 2 options objects specified in typestat.json to modify your source code.
This may take a while...


Starting options object 1 of 2.

Renaming files from JavaScript to TypeScript...
Renamed 1 file from JavaScript to TypeScript.
Done.

Finished options object 1 of 2.


Starting options object 2 of 2.

Starting the core mutation engine. This terminal will log whenever a "wave" of mutations are written to files.
Core mutations will complete when two waves pass with no mutations.
The following fixes will be applied:
	* incompleteTypes
	* missingProperties
	* noImplicitAny

Starting wave 1...
Completed wave 1. Wrote mutations to 1 file.
Starting wave 2...
Completed wave 2. Wrote mutations to 1 file.
Starting wave 3...
Completed wave 3. Wrote mutations to 1 file.
Starting wave 4...
Completed wave 4. Wrote mutations to 1 file.
Starting wave 5...
Completed wave 5. Wrote mutations to 1 file.
Starting wave 6...
Completed wave 6. Wrote mutations to 1 file.
Starting wave 7...
Completed wave 7. Wrote mutations to 1 file.
Starting wave 8...
Completed wave 8. Wrote mutations to 1 file.
Starting wave 9...
Completed wave 9. Wrote mutations to 1 file.
Starting wave 10...
Completed wave 10. Wrote mutations to 1 file.
Starting wave 11...
Completed wave 11. Wrote mutations to 1 file.
Starting wave 12...
Completed wave 12. Wrote mutations to 1 file.
Starting wave 13...
Completed wave 13. Wrote mutations to 1 file.
Starting wave 14...
Completed wave 14. Wrote mutations to 1 file.
Starting wave 15...
Completed wave 15. Wrote mutations to 1 file.
Starting wave 16...
Completed wave 16. Wrote mutations to 1 file.
Starting wave 17...
Completed wave 17. Wrote mutations to 1 file.
Starting wave 18...
Completed wave 18. Wrote mutations to 1 file.
Starting wave 19...
Completed wave 19. Wrote mutations to 1 file.
Starting wave 20...
Completed wave 20. Wrote mutations to 1 file.
Starting wave 21...
Completed wave 21. Wrote mutations to 1 file.
It looks like TypeStat has ended up in an infinite loop.

Bailing out of applying more mutations.

Please file an issue to help us fix the bug for you:

https://github.com/JoshuaKGoldberg/TypeStat

Applying post-fix cleanups...
Done.

Finished options object 2 of 2.


All done! ✨
@JoshuaKGoldberg
Copy link
Owner

👋 Thanks for trying out TypeStat!

When I try the same npx typestat --config typestat.json locally, I get:

Error: ENOENT: no such file or directory, open '/Users/josh/repos/prsm/tsconfig.json'

If I run tsc --init then try again, no source files are found. But if I switch src/ to js/ then all the files in js/ are converted. And it does look like an infinite loop is happening:

function yjsTrace(where: string, source: boolean | Y.YMapEvent<unknown> | boolean | boolean | boolean | boolean | boolean | boolean, what: Y.YMapEvent<unknown>) {

Filed #1285.

Is that the same (and only) issue you're seeing locally? If not, could you please post a full reproduction that I can run locally?

@JoshuaKGoldberg JoshuaKGoldberg added the status: needs reproduction The issue was filed with a missing or incomplete reproduction, and it can't be reproduced locally. label Aug 21, 2023
@micrology
Copy link
Author

micrology commented Aug 21, 2023 via email

@JoshuaKGoldberg
Copy link
Owner

Swell, thanks! Copying the report from #1285:

🐛 Bug Report

  • TypeStat version: 2.1.1
  • TypeScript version: 5.1.6
  • Node version: v20.0.0

Actual Behavior

Original code:

function yjsTrace(where, source, what) {

Result from TypeStat:

function yjsTrace(where: string, source: boolean | Y.YMapEvent<unknown> | boolean | boolean | boolean | boolean | boolean | boolean, what: Y.YMapEvent<unknown>) {

Expected Behavior

function yjsTrace(where: string, source: boolean | Y.YMapEvent<unknown>, what: Y.YMapEvent<unknown>) {

Reproduction

See #1284.

@JoshuaKGoldberg JoshuaKGoldberg added type: bug Something isn't working :( 🐛 status: accepting prs Please, send a pull request to resolve this! 🙏 fixer: no implicit any and removed status: needs reproduction The issue was filed with a missing or incomplete reproduction, and it can't be reproduced locally. labels Aug 21, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title TypeStat has ended up in an infinite loop Bug: Infinite loop adding | boolean to a union typed parameter Aug 21, 2023
@vzendara
Copy link

vzendara commented Aug 22, 2023

Going to echo an infinite loop bug on union type parameters. Ends up terminating with the infinite loop message and repeating union type parameters.

Screen Shot 2023-08-22 at 12 50 01 PM

@JoshuaKGoldberg
Copy link
Owner

@vzipp could you please post a reproduction? It's good to know you're experiencing a variation of this issue, but I can't help you if I have no idea what the rest of your project looks like 🙂

JoshuaKGoldberg pushed a commit that referenced this issue Mar 30, 2024
…1481)

<!-- 👋 Hi, thanks for sending a PR to TypeStat! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [x] Addresses an existing open issue: fixes #1447 - I think it also
fixes #1284
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/TypeStat/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/TypeStat/blob/main/.github/CONTRIBUTING.md)
were taken 😹

## Overview

<!-- Description of what is changed and how the code change does that.
-->

It was this small change in the end??

Note, `async function navigateTo(): Promise<boolean> | boolean {` and
`async function navigateTo2(): Promise<boolean> | boolean {` are wrong.
Both should return only `Promise<boolean>`. I can remove those from the
test but I wanted to keep them to see, the difference.

Co-authored-by: rubiesonthesky <rubiesonthesky>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixer: no implicit any status: accepting prs Please, send a pull request to resolve this! 🙏 type: bug Something isn't working :( 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants