Repository navigation
Fix panic when computing emit signature for fileless diagnostics #65635
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
Open
Shubh (Shubham02022002)
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
Shubham02022002:fix/64875-fileless-diagnostic-panic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tsc/internal/execute/tsctests/tsc_incremental_failed_write_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package tsctests | ||
|
|
||
| import ( | ||
| "io/fs" | ||
| "testing" | ||
| "testing/fstest" | ||
| ) | ||
|
|
||
| func TestTscIncrementalFailedWrite(t *testing.T) { | ||
| t.Parallel() | ||
| test := &tscInput{ | ||
| subScenario: "declaration emit reports failed write without panicking", | ||
| files: FileMap{ | ||
| "/home/src/workspaces/project/tsconfig.json": `{"compilerOptions":{"incremental":true,"declaration":true,"rootDir":"src","outDir":"dist"}}`, | ||
| "/home/src/workspaces/project/src/a.ts": `export const a = 1;`, | ||
| // A directory where the JS output goes makes the write fail with TS5033. | ||
| "/home/src/workspaces/project/dist/a.js": &fstest.MapFile{Mode: fs.ModeDir | 0o777}, | ||
| }, | ||
| commandLineArgs: []string{"-p", "."}, | ||
| } | ||
| test.run(t, "incremental") | ||
| } |
116 changes: 116 additions & 0 deletions
116
...ines/reference/tsc/incremental/declaration-emit-reports-failed-write-without-panicking.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| currentDirectory::/home/src/workspaces/project | ||
| useCaseSensitiveFileNames::true | ||
| Input:: | ||
| //// [/home/src/workspaces/project/src/a.ts] *new* | ||
| export const a = 1; | ||
| //// [/home/src/workspaces/project/tsconfig.json] *new* | ||
| {"compilerOptions":{"incremental":true,"declaration":true,"rootDir":"src","outDir":"dist"}} | ||
|
|
||
| tsc -p . | ||
| ExitStatus:: DiagnosticsPresent_OutputsGenerated | ||
| Output:: | ||
| [91merror[0m[90m TS5033: [0mCould not write file '/home/src/workspaces/project/dist/a.js': write "home/src/workspaces/project/dist/a.js": path exists but is not a regular file. | ||
|
|
||
| Found 1 error. | ||
|
|
||
| //// [/home/src/tslibs/TS/Lib/lib.es2026.full.d.ts] *Lib* | ||
| /// <reference no-default-lib="true"/> | ||
| interface Boolean {} | ||
| interface Function {} | ||
| interface CallableFunction {} | ||
| interface NewableFunction {} | ||
| interface IArguments {} | ||
| interface Number { toExponential: any; } | ||
| interface Object {} | ||
| interface RegExp {} | ||
| interface String { charAt: any; } | ||
| interface Array<T> { length: number; [n: number]: T; } | ||
| interface ReadonlyArray<T> {} | ||
| interface SymbolConstructor { | ||
| (desc?: string | number): symbol; | ||
| for(name: string): symbol; | ||
| readonly toStringTag: symbol; | ||
| } | ||
| declare var Symbol: SymbolConstructor; | ||
| interface Symbol { | ||
| readonly [Symbol.toStringTag]: string; | ||
| } | ||
| declare const console: { log(msg: any): void; }; | ||
| //// [/home/src/workspaces/project/dist/a.d.ts] *new* | ||
| export declare const a = 1; | ||
|
|
||
| //// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new* | ||
| {"version":"FakeTSVersion","root":[2],"fileNames":["lib.es2026.full.d.ts","./src/a.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"f5c8fff6e1fca35f4a292d48868d4086-export const a = 1;","signature":"67cd7ccc14045107336f34154f76a8ca-export declare const a = 1;\n","impliedNodeFormat":1}],"options":{"declaration":true,"outDir":"./dist","rootDir":"./src"},"emitDiagnosticsPerFile":[[2,[{"noFile":true,"pos":-1,"end":-1,"code":5033,"category":1,"messageKey":"Could_not_write_file_0_Colon_1_5033","messageArgs":["/home/src/workspaces/project/dist/a.js","write \"home/src/workspaces/project/dist/a.js\": path exists but is not a regular file"]}]]]} | ||
| //// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new* | ||
| { | ||
| "version": "FakeTSVersion", | ||
| "root": [ | ||
| { | ||
| "files": [ | ||
| "./src/a.ts" | ||
| ], | ||
| "original": 2 | ||
| } | ||
| ], | ||
| "fileNames": [ | ||
| "lib.es2026.full.d.ts", | ||
| "./src/a.ts" | ||
| ], | ||
| "fileInfos": [ | ||
| { | ||
| "fileName": "lib.es2026.full.d.ts", | ||
| "version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };", | ||
| "signature": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };", | ||
| "affectsGlobalScope": true, | ||
| "impliedNodeFormat": "CommonJS", | ||
| "original": { | ||
| "version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };", | ||
| "affectsGlobalScope": true, | ||
| "impliedNodeFormat": 1 | ||
| } | ||
| }, | ||
| { | ||
| "fileName": "./src/a.ts", | ||
| "version": "f5c8fff6e1fca35f4a292d48868d4086-export const a = 1;", | ||
| "signature": "67cd7ccc14045107336f34154f76a8ca-export declare const a = 1;\n", | ||
| "impliedNodeFormat": "CommonJS", | ||
| "original": { | ||
| "version": "f5c8fff6e1fca35f4a292d48868d4086-export const a = 1;", | ||
| "signature": "67cd7ccc14045107336f34154f76a8ca-export declare const a = 1;\n", | ||
| "impliedNodeFormat": 1 | ||
| } | ||
| } | ||
| ], | ||
| "options": { | ||
| "declaration": true, | ||
| "outDir": "./dist", | ||
| "rootDir": "./src" | ||
| }, | ||
| "emitDiagnosticsPerFile": [ | ||
| [ | ||
| "./src/a.ts", | ||
| [ | ||
| { | ||
| "noFile": true, | ||
| "pos": -1, | ||
| "end": -1, | ||
| "code": 5033, | ||
| "category": 1, | ||
| "messageKey": "Could_not_write_file_0_Colon_1_5033", | ||
| "messageArgs": [ | ||
| "/home/src/workspaces/project/dist/a.js", | ||
| "write \"home/src/workspaces/project/dist/a.js\": path exists but is not a regular file" | ||
| ] | ||
| } | ||
| ] | ||
| ] | ||
| ], | ||
| "size": 1394 | ||
| } | ||
|
|
||
| tsconfig.json:: | ||
| SemanticDiagnostics:: | ||
| *refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts | ||
| *refresh* /home/src/workspaces/project/src/a.ts | ||
| Signatures:: | ||
| (stored at emit) /home/src/workspaces/project/src/a.ts |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — kept the nil guard and excluded TS5033 from
computeSignatureWithDiagnostics, so a failed write no longer affects the stored declaration signature. Regenerated the baseline; the signature is now just the d.ts hash.npx hereby validatepasses.