Add check for nil symbol in getJSDocOrTag#2763
Conversation
|
Don't think we need a test here, it was just a missing |
There was a problem hiding this comment.
Pull request overview
Fixes a language-service hover panic by guarding against a nil base type symbol when retrieving JSDoc for inherited static members (issue #2720).
Changes:
- Add a nil check for
baseType.Symbol()before callingGetTypeOfSymbolingetJSDocOrTag.
| t := baseType | ||
| if isStatic { | ||
| if isStatic && baseType.Symbol() != nil { | ||
| t = c.GetTypeOfSymbol(baseType.Symbol()) |
There was a problem hiding this comment.
Please add a regression test for this panic. getJSDocOrTag is invoked during hover, and this change is specifically preventing a nil-deref crash; having a focused test (e.g., in internal/ls/hover_test.go) that exercises the static-member + base type with nil Symbol() path would help ensure it doesn’t regress again.
| if isStatic && baseType.Symbol() != nil { | ||
| t = c.GetTypeOfSymbol(baseType.Symbol()) |
There was a problem hiding this comment.
Minor: this calls baseType.Symbol() twice on the same value. Consider assigning it to a local (e.g., baseSym := baseType.Symbol()) to make the nil-check and subsequent use clearer and avoid duplicate calls.
| if isStatic && baseType.Symbol() != nil { | |
| t = c.GetTypeOfSymbol(baseType.Symbol()) | |
| baseSym := baseType.Symbol() | |
| if isStatic && baseSym != nil { | |
| t = c.GetTypeOfSymbol(baseSym) |
|
Added regression test by popular demand. |
Fixes #2720.