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

Crashes on transform and parse (from assertion/debug failures) #58924

Open
Roise-yue opened this issue Jun 19, 2024 · 5 comments · Fixed by #58963
Open

Crashes on transform and parse (from assertion/debug failures) #58924

Roise-yue opened this issue Jun 19, 2024 · 5 comments · Fixed by #58963
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Domain: Transforms Relates to the public transform API Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@Roise-yue
Copy link

🔎 Search Terms

Debug Failure,modifierVisitor

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 5.2__ and _5.3(Both versions 4.7-5.2 and 5.2-5.4.5 reported Debug Failure errors, but the error information is different)

⏯ Playground Link

No response

💻 Code

I did not use tsc to execute any ts programs, but instead used the command "node --max-old-space-size=10240 $(which tsc)" to increase the memory of node.js.
When the version of tsc is between 5.3 and 5.4.5, the debugging error message is in “error message 1 "of "Actual behavior", and when the version of tsc is between 4.7 and 5.2, the debugging error message is in "error message 2" of "Actual behavior". I did not test versions before version 4.7
(The relevant version and configuration information are written in "Additional information about the issue")

🙁 Actual behavior

error message 1:
/usr/lib/node_modules/typescript/lib/tsc.js:118651
throw e;
^

Error: Debug Failure. Use modifierVisitor instead.
at visitor (/usr/lib/node_modules/typescript/lib/tsc.js:90424:22)
at visitArrayWorker (/usr/lib/node_modules/typescript/lib/tsc.js:85608:49)
at visitNodes2 (/usr/lib/node_modules/typescript/lib/tsc.js:85579:19)
at visitEachChildOfVariableStatement (/usr/lib/node_modules/typescript/lib/tsc.js:86379:7)
at visitEachChild (/usr/lib/node_modules/typescript/lib/tsc.js:85796:33)
at visitVariableStatement (/usr/lib/node_modules/typescript/lib/tsc.js:90639:25)
at visitor (/usr/lib/node_modules/typescript/lib/tsc.js:90435:16)
at visitArrayWorker (/usr/lib/node_modules/typescript/lib/tsc.js:85608:49)
at visitNodes2 (/usr/lib/node_modules/typescript/lib/tsc.js:85579:19)
at visitLexicalEnvironment (/usr/lib/node_modules/typescript/lib/tsc.js:85635:16)

error message 2:
/usr/lib/node_modules/typescript/lib/tsc.js:2099
throw e;
^

Error: Debug Failure. Expected 23 <= 22
at attachFileToDiagnostic (/usr/lib/node_modules/typescript/lib/tsc.js:15670:30)
at Object.attachFileToDiagnostics (/usr/lib/node_modules/typescript/lib/tsc.js:15684:42)
at parseSourceFileWorker (/usr/lib/node_modules/typescript/lib/tsc.js:25347:46)
at Object.parseSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:25183:26)
at Object.createSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:25087:29)
at Object.getSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:95276:44)
at compilerHost.getSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:101685:53)
at findSourceFileWorker (/usr/lib/node_modules/typescript/lib/tsc.js:97446:29)
at findSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:97364:26)
at /usr/lib/node_modules/typescript/lib/tsc.js:97318:85

🙂 Expected behavior

Expand the memory of node.js without any errors.

Additional information about the issue

node.js:v20.14.0 and 14.21.3(tried two versions and the result is the same)
tsc:Version 4.7.2-5.4.5

package.json
{
"name": "tscfuzz",
"version": "1.0.0",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "nyc --reporter=text --reporter=lcov mocha "
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.24.7",
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"jshint": "^2.13.6",
"mocha": "^10.4.0",
"nyc": "^15.1.0"
},
"dependencies": {},
"description": ""
}

tsconfig.json
{
"compilerOptions": {
"incremental": true,
"target": "es6",
"lib": ["es2022"],
"module": "commonjs",
"sourceMap": true,
"inlineSourceMap": true,
"inlineSources": true,
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
}
}

@Andarist
Copy link
Contributor

Could you try to narrow it down? It's almost impossible to fix this without knowing what source files lead to the problem.

@DanielRosenwasser
Copy link
Member

Yes, one thing you could try is to keep deleting files until you've found a culprit. Then when you've narrowed things down to as few files as possible, try to delete as many lines of code as you can.

@Roise-yue
Copy link
Author

I have filtered out the ts files that can cause the above problem and located the code lines in the files that may cause errors.
I have modified tsconfig.json,and used version 5.4.5 of the tsc testing program on the Ubuntu 22.04.3 LTS platform.

I have provided configuration files, TS source files, and specific error messages in this repository:https://github.com/Roise-yue/tscFuzz

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Transforms Relates to the public transform API labels Jun 20, 2024
@DanielRosenwasser
Copy link
Member

Thank you so much for finding these @Roise-yue! I'm copying those files into this comment to make it easier to follow - the transform crash is from the use of the accessor keyword used in certain spots:

// @target: esnext
// @noTypesAndSymbols: true

abstract class C1 {
    accessor accessor a: any;
    readonly accessor b: any;
    declare accessor c: any;
    accessor public d: any;
    accessor private e: any;
    accessor protected f: any;
    accessor abstract g: any;
    accessor static h: any;
    accessor i() {}
    accessor get j() { return false; }
    accessor set k(v: any) {}
    accessor constructor() {}
    accessor l?: any;
    accessor readonly m: any;
    accessor declare n: any;
}

class C2 extends C1 {
    accessor override g: any;
}

interface I1 {
    accessor a: number;
}

accessor class C3 {}
accessor interface I2 {}
accessor namespace N1 {}
accessor enum E1 {}   // Error location
accessor var V1: any;
accessor type T1 = never;
accessor function F1() {}
accessor import "x";
accessor import {} from "x";
accessor export { V1 };
accessor export default V1;
accessor import N2 = N1;

(Playground link here)

And the other error I haven't been able to verify independently, but I'm pasting it here.

// @importHelpers: true
// @target: es5
// @module: commonjs
// @moduleResolution: classic
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @filename: external.ts
export * from "./other";
export class A { }
export class B extends A { }

declare var dec: any;

@dec
class C {
    method(@dec x: number) {    // Error location
    }
}

const o = { a: 1 };
const y = { ...o };
const { ...x } = y;

// @filename: other.ts
export const x = 1;

// @filename: script.ts
class A { }
class B extends A { }

declare var dec: any;

@dec
class C {
    method(@dec x: number) {
    }
}

// @filename: tslib.d.ts
export {}

@DanielRosenwasser DanielRosenwasser added Help Wanted You can do this Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Jun 20, 2024
@DanielRosenwasser DanielRosenwasser changed the title Debug Failure Crashes on transform and parse (from assertion/debug failures) Jun 20, 2024
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jun 21, 2024
@rbuckton rbuckton reopened this Jun 24, 2024
@codewithsupra
Copy link

I summarized some of the details from the previous comments to help others follow along:

  • The crash occurs when using accessor in unexpected ways (e.g., in enum, var, or as a function).
  • It affects TypeScript versions from 4.7 to 5.4.5.
  • Here are some of the problematic examples:
    accessor enum E1 {}
    accessor var V1: any;
    accessor function F1() {}

Hope this helps in organizing information for anyone looking into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Domain: Transforms Relates to the public transform API Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants