Skip to content

[WIP] Fix crash during compilation of SubTup type#2928

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-compilation-crash
Open

[WIP] Fix crash during compilation of SubTup type#2928
Copilot wants to merge 3 commits intomainfrom
copilot/fix-compilation-crash

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

  • Investigate crash with infer + rest/variadic tuple elements
  • Identify root cause: nil pointer dereference in inferFromObjectTypes when getElementTypeOfSliceOfTupleType returns nil
  • Add nil guards at both affected locations in internal/checker/inference.go
  • Add compiler test case inferFromTupleRestAndVariadic.ts with baselines
  • Verify the fix resolves the crash
  • Run related inference+tuple tests to confirm no regressions
  • Code review and security scan — no issues found

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits February 27, 2026 17:53
When inferring from tuple types with a mix of rest and variadic elements
(e.g. [...rest, ...T] or [...T, ...rest]), getElementTypeOfSliceOfTupleType
can return nil when the variadic element's implied arity consumes all
source tuple elements. The nil return value was passed directly to
inferFromTypes, causing a nil pointer dereference at inference.go:79.

Added nil guards consistent with the existing pattern used elsewhere in
the same function (line ~736). When getElementTypeOfSliceOfTupleType
returns nil, we skip the inference call since there are no remaining
source elements to infer from.

This bug also exists in the TypeScript compiler (tsc crashes with
TypeError on the same input), so this fix diverges from the TS source
to prevent the crash in Go.
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@RyanCavanaugh RyanCavanaugh marked this pull request as ready for review February 27, 2026 18:05
Copilot AI review requested due to automatic review settings February 27, 2026 18:05
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 crash during compilation when inferring from tuple types with rest and variadic elements. The crash occurred when a variadic element's constraint consumed all source tuple elements, causing getElementTypeOfSliceOfTupleType to return nil, leading to a nil pointer dereference.

Changes:

  • Added nil guards at two locations in inferFromObjectTypes where getElementTypeOfSliceOfTupleType could return nil
  • Added comprehensive compiler test case inferFromTupleRestAndVariadic.ts covering both [...rest, ...T] and [...T, ...rest] patterns
  • Accepted baselines showing correct type inference behavior

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testdata/tests/cases/compiler/inferFromTupleRestAndVariadic.ts New compiler test with edge cases for tuple inference with rest and variadic elements
testdata/baselines/reference/compiler/inferFromTupleRestAndVariadic.types Type inference baseline showing correct results for all test cases
testdata/baselines/reference/compiler/inferFromTupleRestAndVariadic.symbols Symbol resolution baseline for the test cases
testdata/baselines/reference/compiler/inferFromTupleRestAndVariadic.js JavaScript emit baseline for the test cases
internal/checker/inference.go Added nil guards before calling inferFromTypes with result from getElementTypeOfSliceOfTupleType

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.

3 participants