Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions internal/fourslash/tests/hoverNilBaseSymbolIntersection_test.go
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)
}
2 changes: 1 addition & 1 deletion internal/ls/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 511 to 513
Copy link

Copilot AI Feb 11, 2026

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. 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.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +512 to 513
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if isStatic && baseType.Symbol() != nil {
t = c.GetTypeOfSymbol(baseType.Symbol())
baseSym := baseType.Symbol()
if isStatic && baseSym != nil {
t = c.GetTypeOfSymbol(baseSym)

Copilot uses AI. Check for mistakes.
}
if prop := c.GetPropertyOfType(t, symbol.Name); prop != nil && prop.ValueDeclaration != nil {
Expand Down
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
}
}
}
}
]