-
Notifications
You must be signed in to change notification settings - Fork 958
Fix panic on CLI --typeRoots with relative path
#3866
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -642,6 +642,14 @@ func ConvertOptionToAbsolutePath(o string, v any, optionMap CommandLineOptionNam | |
| return tspath.GetNormalizedAbsolutePath(item, cwd) | ||
| }), true | ||
| } | ||
| if arr, ok := v.([]any); ok { | ||
| return core.Map(arr, func(item any) any { | ||
| if s, isStr := item.(string); isStr { | ||
| return tspath.GetNormalizedAbsolutePath(s, cwd) | ||
| } | ||
| return item | ||
| }), true | ||
| } | ||
|
Comment on lines
642
to
+652
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That won't work, slices are invariant
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, Go slices are invariant so |
||
| } | ||
| } else if option.IsFilePath { | ||
| if value, ok := v.(string); ok { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| error TS2688: Cannot find type definition file for 'n'. | ||
| The file is in the program because: | ||
| Entry point of type library 'n' specified in compilerOptions | ||
|
|
||
|
|
||
| !!! error TS2688: Cannot find type definition file for 'n'. | ||
| !!! error TS2688: The file is in the program because: | ||
| !!! error TS2688: Entry point of type library 'n' specified in compilerOptions | ||
| ==== typeRootsRelativePath.ts (0 errors) ==== | ||
| let x = 1; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| //// [tests/cases/compiler/typeRootsRelativePath.ts] //// | ||
|
|
||
| === typeRootsRelativePath.ts === | ||
| let x = 1; | ||
| >x : Symbol(x, Decl(typeRootsRelativePath.ts, 0, 3)) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| //// [tests/cases/compiler/typeRootsRelativePath.ts] //// | ||
|
|
||
| === typeRootsRelativePath.ts === | ||
| let x = 1; | ||
| >x : number | ||
| >1 : 1 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // @typeRoots: t | ||
| // @types: n | ||
| // @noEmit: true | ||
|
|
||
| let x = 1; |
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.
@copilot investigate
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.
The reviewer was correct — the compiler test exercises the
[]stringpath via the test harness (which manually normalizesTypeRootson lines 183-185 ofharnessutil.go), not the[]anyCLI parser path. Added a unit testTestParseCommandLineTypeRootsRelativePathin 97e9f6b that callsParseCommandLinewith--typeRoots tand asserts the result is an absolute path, directly exercising the[]anybranch.