Skip to content

fix: a panic in prealloc when analyzing malformed or partially reco… - #66

Merged
alexkohler merged 1 commit into
alexkohler:masterfrom
Laisky:master
Feb 10, 2026
Merged

fix: a panic in prealloc when analyzing malformed or partially reco…#66
alexkohler merged 1 commit into
alexkohler:masterfrom
Laisky:master

Conversation

@Laisky

@Laisky Laisky commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a panic in prealloc when analyzing malformed or partially recovered AST nodes.

The panic happened because type inference assumed multi-value declarations/assignments always had at least one RHS expression, and accessed index 0 unconditionally.

Changes

  • Add defensive checks in pkg/types.go:
    • inferValueType: return nil when len(value.Values) == 0
    • inferAssignType: return nil when len(assign.Rhs) == 0
  • Add regression tests in pkg/types_test.go to ensure:
    • no panic for empty ValueSpec values
    • no panic for empty assignment RHS
    • no panic in end-to-end Check on malformed source

Compatibility

This is a backward-compatible hardening change:

  • behavior for valid code is unchanged
  • malformed/incomplete inputs now fail safely instead of panicking

Copilot AI review requested due to automatic review settings February 9, 2026 15:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Hardens prealloc’s internal type inference against malformed / partially recovered AST nodes to avoid panics during analysis.

Changes:

  • Add defensive empty-slice checks in inferValueType and inferAssignType to avoid indexing into missing RHS/value lists.
  • Add regression tests covering empty ValueSpec values, empty assignment RHS, and an end-to-end Check run on malformed parsed source.

Reviewed changes

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

File Description
pkg/types.go Adds guards returning nil when ValueSpec.Values / AssignStmt.Rhs are empty to prevent panics.
pkg/types_test.go Introduces regression tests ensuring the analyzer doesn’t panic on malformed/partial AST shapes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alexkohler alexkohler left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you! 🚀

@alexkohler
alexkohler merged commit 43d244a into alexkohler:master Feb 10, 2026
6 of 7 checks passed
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