-
Notifications
You must be signed in to change notification settings - Fork 829
Add check for nil symbol in getJSDocOrTag
#2763
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
Merged
+79
−1
Merged
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
32 changes: 32 additions & 0 deletions
32
internal/fourslash/tests/hoverNilBaseSymbolIntersection_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,32 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestHoverNilBaseSymbolIntersection(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
|
|
||
| const content = ` | ||
| // @strict: true | ||
| // @filename: main.ts | ||
|
|
||
| class Base {} | ||
|
|
||
| declare const BaseFactory: new() => Base & { c: string }; | ||
|
|
||
| class Derived extends BaseFactory { | ||
| static /*1*/idField = "id" as const; | ||
| } | ||
| ` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
|
|
||
| // We only care that hover/quickinfo does not crash (panic) when baseType.Symbol() is nil. | ||
| // Pre-fix (#2763), hovering on the static property could panic in getJSDocOrTag. | ||
| f.VerifyBaselineHover(t) | ||
| } |
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -509,7 +509,7 @@ func getJSDocOrTag(c *checker.Checker, node *ast.Node) *ast.Node { | |||||||||||
| isStatic := ast.HasStaticModifier(node) | ||||||||||||
| for _, baseType := range c.GetBaseTypes(c.GetDeclaredTypeOfSymbol(node.Parent.Symbol())) { | ||||||||||||
| t := baseType | ||||||||||||
| if isStatic { | ||||||||||||
| if isStatic && baseType.Symbol() != nil { | ||||||||||||
| t = c.GetTypeOfSymbol(baseType.Symbol()) | ||||||||||||
|
Comment on lines
+512
to
513
|
||||||||||||
| if isStatic && baseType.Symbol() != nil { | |
| t = c.GetTypeOfSymbol(baseType.Symbol()) | |
| baseSym := baseType.Symbol() | |
| if isStatic && baseSym != nil { | |
| t = c.GetTypeOfSymbol(baseSym) |
46 changes: 46 additions & 0 deletions
46
testdata/baselines/reference/fourslash/quickInfo/hoverNilBaseSymbolIntersection.baseline
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,46 @@ | ||
| // === QuickInfo === | ||
| === /main.ts === | ||
| // class Base {} | ||
| // | ||
| // declare const BaseFactory: new() => Base & { c: string }; | ||
| // | ||
| // class Derived extends BaseFactory { | ||
| // static idField = "id" as const; | ||
| // ^^^^^^^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | ```tsx | ||
| // | (property) Derived.idField: "id" | ||
| // | ``` | ||
| // | | ||
| // | ---------------------------------------------------------------------- | ||
| // } | ||
| // | ||
| [ | ||
| { | ||
| "marker": { | ||
| "Position": 119, | ||
| "LSPosition": { | ||
| "line": 5, | ||
| "character": 9 | ||
| }, | ||
| "Name": "1", | ||
| "Data": {} | ||
| }, | ||
| "item": { | ||
| "contents": { | ||
| "kind": "markdown", | ||
| "value": "```tsx\n(property) Derived.idField: \"id\"\n```\n" | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 5, | ||
| "character": 9 | ||
| }, | ||
| "end": { | ||
| "line": 5, | ||
| "character": 16 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] |
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.
Please add a regression test for this panic.
getJSDocOrTagis invoked during hover, and this change is specifically preventing a nil-deref crash; having a focused test (e.g., ininternal/ls/hover_test.go) that exercises the static-member + base type with nilSymbol()path would help ensure it doesn’t regress again.