-
Notifications
You must be signed in to change notification settings - Fork 760
Fix nil pointer dereference in completion at property start after JSDoc #2259
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
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/fix-javadoc-completion-crash
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.
+51
−2
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e823278
Initial plan
Copilot 9654302
Add test case for JSDoc before property completion crash
Copilot ddf52a6
Fix crash when completing at beginning of property name preceded by J…
Copilot e64582b
Merge branch 'main' into copilot/fix-javadoc-completion-crash
DanielRosenwasser 4c877f7
Remove unnecessary defensive nil checks, keep only the actual fix
Copilot d55224e
Merge remote-tracking branch 'origin/main' into copilot/fix-javadoc-c…
Copilot 27b3371
Fix crash with nil contextToken and add test
Copilot 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
49 changes: 49 additions & 0 deletions
49
internal/fourslash/tests/completionJSDocBeforeProperty_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,49 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| // Test for: Crash completing beginning of property name when preceded by JSDoc | ||
| // This test verifies that requesting completions at the beginning of a property name | ||
| // preceded by JSDoc does not cause a crash. The crash was caused by a nil pointer | ||
| // dereference when contextToken was nil. | ||
| func TestCompletionJSDocBeforePropertyNoCrash(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `export class SomeInterface { | ||
| /** ruh-roh! */ | ||
| /*a*/property: string; | ||
| } | ||
|
|
||
| export class SomeClass { | ||
| /** ruh-roh! */ | ||
| /*b*/property = "value"; | ||
| }` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
| // The primary goal of this test is to ensure no panic occurs when requesting completions. | ||
| // The testutil.RecoverAndFail defer will catch any panic and fail the test. | ||
| // We verify completions can be requested successfully without checking specific completion items. | ||
| f.VerifyCompletions(t, "a", &fourslash.CompletionsExpectedList{ | ||
| ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ | ||
| CommitCharacters: &[]string{".", ",", ";"}, | ||
| EditRange: fourslash.Ignored{}, | ||
| }, | ||
| Items: &fourslash.CompletionsExpectedItems{ | ||
| Includes: []fourslash.CompletionsExpectedItem{}, | ||
| }, | ||
| }) | ||
| f.VerifyCompletions(t, "b", &fourslash.CompletionsExpectedList{ | ||
| ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ | ||
| CommitCharacters: &[]string{".", ",", ";"}, | ||
| EditRange: fourslash.Ignored{}, | ||
| }, | ||
| Items: &fourslash.CompletionsExpectedItems{ | ||
| Includes: []fourslash.CompletionsExpectedItem{}, | ||
| }, | ||
| }) | ||
| } |
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
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.
this can't possibly do anything anymore...
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.
You're right - the variable shadowing fix alone wasn't sufficient. The issue was that
tryGetObjectTypeDeclarationCompletionContainercould return a non-nil declaration even whencontextTokenwas nil (specifically in the Identifier case at line 4166). I've added a nil check there:if contextToken != nil && isFromObjectTypeDeclaration(location)(commit 27b3371).