TypeStat icon indicating copy to clipboard operation
TypeStat copied to clipboard

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

Open micrology opened this issue 2 years ago • 5 comments

🐛 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! ✨

micrology avatar Aug 21 '23 15:08 micrology

👋 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 avatar Aug 21 '23 16:08 JoshuaKGoldberg

Hi,

Apologies: I was running TypeStat locally, having copied the prsm.js file into a ./src directory to test what TypeStat does, but then pointed you to the file where it is located on GitHub when filing the error report.

So to confirm, the issue you found is the same and only issue I am seeing.

Thanks for your quick response – good luck with finding the problem.

Nigel

micrology avatar Aug 21 '23 16:08 micrology

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 avatar Aug 21 '23 16:08 JoshuaKGoldberg

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

vzendara avatar Aug 22 '23 16:08 vzendara

@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 avatar Aug 22 '23 21:08 JoshuaKGoldberg