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: [no-unsafe-argument] Maximum call stack size exceeded for recursive types #7298

Closed
4 tasks done
mxgr7 opened this issue Jul 23, 2023 · 3 comments · Fixed by #8237
Closed
4 tasks done

Bug: [no-unsafe-argument] Maximum call stack size exceeded for recursive types #7298

mxgr7 opened this issue Jul 23, 2023 · 3 comments · Fixed by #8237
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@mxgr7
Copy link

mxgr7 commented Jul 23, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.1.6&fileType=.tsx&code=FAFwngDgpgBAKgJyrAvDA2gOwK4FsBGUCANPElOgLqXDABm2mAxiAJYD2mMuAhhIsgAUIcgC4yyUnUzjBMmDgJEAlDBQA%2BBXkIJl4gbADewGDCacAziAyYp7JFcpqYI5CZhIQ2BF3TS5ynYOIAB0vBCCwvrkqhrcfAbCUpjKyjQAvkA&eslintrc=N4KABGBEAOCGBOBnApvSAuKABALgT2mUQGN4BLaHAWiIBsyA7HAejiVUgBpwp4BXWkQxhQECJFwEipCtTqMWDAPZU%2BDRLABmyKggDmfALbImwyKnhK0PAL4gbQA&tsconfig=N4XyA&tokens=false

Repro Code

type Tree = [number, Tree[]]

function mapTree(tree: Tree, fn: (n: number) => number): Tree {
  const [n, forest] = tree
  return [fn(n), forest.map(t => mapTree(t, fn))]
}

ESLint Config

{
  "parser": "@typescript-eslint/parser",
  "rules": {
    "@typescript-eslint/no-unsafe-argument": "error"
  }
}

tsconfig

{}

Expected Result

I expect eslint to run without errors.

Actual Result

RangeError: Maximum call stack size exceeded
Occurred while linting /input.tsx:6
Rule: "@typescript-eslint/no-unsafe-argument"
    at Mt (https://typescript-eslint.io/sandbox/index.js:111:214546)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215466)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
    at Da (https://typescript-eslint.io/sandbox/index.js:111:215803) 6:42 - 6:56

Additional Info

It works if I add an explicit empty array as alternative type:
type Tree = [number, Tree[] | []]
instead of:
type Tree = [number, Tree[]]

See playground example.

type Tree = [number, Tree[] | []]

function mapTree(tree: Tree, fn: (n: number) => number): Tree {
  const [n, forest] = tree
  return [fn(n), forest.map((t: Tree) => mapTree(t, fn))]
}

Result:

All is ok!
@mxgr7 mxgr7 added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jul 23, 2023
@auvred
Copy link
Member

auvred commented Jul 24, 2023

Minimal reproduction: playground

It seems that infinite recursion occurs in this function

const unsafe = isUnsafeAssignment(arg, receiverArg, checker, senderNode);

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Jul 24, 2023
@jkowalleck
Copy link

jkowalleck commented Dec 10, 2023

any updates here?

here is my reproducible setup: https://github.com/CycloneDX/cyclonedx-node-npm/tree/87bb87b7ee50f8625c53c84dbba98a75aa56d105
error: https://github.com/CycloneDX/cyclonedx-node-npm/actions/runs/7158496762/job/19490649544?pr=1134#step:5:19

ops! Something went wrong! :(

ESLint: 8.55.0

RangeError: Maximum call stack size exceeded
Occurred while linting /home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/src/builders.ts:249
Rule: "@typescript-eslint/no-unsafe-argument"
    at isTypeAnyType (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/predicates.js:97:23)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:41:40)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)
    at isUnsafeAssignment (/home/runner/work/cyclonedx-node-npm/cyclonedx-node-npm/node_modules/@typescript-eslint/type-utils/dist/isUnsafeAssignment.js:83:28)

@bradzacher
Copy link
Member

We are a community run project. The volunteer maintainers spend most of their time triaging issues and reviewing PRs. This means that most issues will not progress unless a member of the community steps up and champions it.

If this issue is important to you — consider being that champion.
If not — please use the subscribe function and wait patiently for someone else to implement this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants