-
Notifications
You must be signed in to change notification settings - Fork 804
Fix nil pointer panic in JSDoc callable type completions #2491
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
base: main
Are you sure you want to change the base?
Conversation
Add nil check before accessing paramSymbol.Name to prevent panic when paramSymbol is nil in JSDoc callable type signatures with parameters. Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
|
I feel like the investigation here is good but I don't understand why the parameter didn't have a symbol. |
|
The parameter doesn't have a symbol because we don't do any binding on symbols in JSDoc comments. The declaration of |
|
@ahejlsberg said that the real issue is that we need to get the reparsed node (via |
Instead of adding a nil check, get the reparsed parameter node which has the symbol properly attached during binding. JSDoc parameters don't have symbols because JSDoc comments aren't bound, but the reparsed versions (created during type resolution) do have symbols. Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Fixed in 764a038. I exported |
|
We think the call to |
After investigation, calling GetNodeAtPosition (needed for getReparsedNodeForNode) during type checking causes performance issues. The simpler nil check approach is more appropriate for this location in the code. Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
I investigated using Fixed in f000b0e by keeping the simple nil check approach, which is the minimal, safe fix for this location in |
Requesting completions in a JSDoc callable type signature with parameters causes a nil pointer dereference:
Root Cause
JSDoc parameters don't have symbols attached during binding because JSDoc comments aren't bound during the binding phase. The original code was trying to access
paramSymbol.Namewithout checking ifparamSymbolis nil.Changes
checker.go: Add nil check before accessing
paramSymbol.NameingetSignatureFromDeclarationif i == 0 && paramSymbol.Name == ...toif i == 0 && paramSymbol != nil && paramSymbol.Name == ...Test: Add reproduction case
TestJsDocCompletionUnionReturnTypeWithParamsNoCrashInvestigation Notes
During implementation, I investigated using
getReparsedNodeForNodeto access symbols from reparsed nodes (which do have symbols attached). However, this approach requires callingGetNodeAtPosition, which causes performance issues and test hangs when called during type checking. ThegetReparsedNodeForNodefunction is currently only used in language service code after binding/type checking completes.The simple nil check is the appropriate, minimal fix for this location in the type checker.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.