Skip to content

Conversation

@DanielRosenwasser
Copy link
Member

Fixes #2332.

Copilot AI review requested due to automatic review settings December 11, 2025 01:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where completions in JSX tags with unstructured spread elements would cause a crash. The fix adds a type check before attempting to access properties on spread types, preventing nil pointer dereferences when the spread type is primitive (e.g., any, unknown, never, number).

Key Changes

  • Added a TypeFlagsStructuredType check before calling AsStructuredType().Properties() to prevent crashes on primitive types
  • Added comprehensive test coverage for various spread element types in JSX tags, including both structured types (objects, unions) and primitive types (any, unknown, never, undefined, number, boolean)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/ls/completions.go Adds type flag validation to ensure only structured types (Object, Union, Intersection) attempt property access, preventing nil pointer dereferences
internal/fourslash/tests/completionsInJsxTagDifferentSpreadElementTypes_test.go New test file verifying completions work correctly for JSX spread elements with various type categories

}

// Very unexpected, but still structured (union) types.
// `boolean` is `true | false` and an optional `null` is really `null | undefined`.
Copy link
Member

Choose a reason for hiding this comment

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

You can't put ` in the test content, unless you concatenate the pieces (it's very annoying) 🙁

Copy link
Member Author

Choose a reason for hiding this comment

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

Oof!

@DanielRosenwasser DanielRosenwasser added this pull request to the merge queue Dec 11, 2025
Merged via the queue into main with commit ddf0b72 Dec 11, 2025
22 checks passed
@DanielRosenwasser DanielRosenwasser deleted the completionsJsxTagWithUnstructuredSpread branch December 11, 2025 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in JSX tag when spread element is non-structured type

4 participants