Skip to content

Fix out of bounds error in recreateBindingPattern #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025

Conversation

AlCalzone
Copy link
Contributor

If the length of the array is 1, the first item is at index 0, not index 1.

If the length of the array is 1, the first item is at index 0, not index 1.
@Copilot Copilot AI review requested due to automatic review settings July 1, 2025 12:20
Copy link
Contributor

@Copilot 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 an out-of-bounds error in the recreateBindingPattern function when the results slice has exactly one element.

  • Corrects the index used for single-element results from 1 to 0
  • Ensures the only element is returned instead of causing an OOB panic
Comments suppressed due to low confidence (1)

internal/transformers/declarations/transform.go:669

  • Add a test case for recreateBindingPattern when results has exactly one element to verify it returns the correct node and avoids out-of-bounds access.
	if len(results) == 1 {
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Seems obviously correct, but how did you find this? Is there a test case?

@AlCalzone
Copy link
Contributor Author

I tried fixing the other issue I reported and caused a panic on a lot of tests.

@jakebailey jakebailey added this pull request to the merge queue Jul 1, 2025
Merged via the queue into microsoft:main with commit ce04369 Jul 1, 2025
22 checks passed
@Andarist
Copy link
Contributor

Andarist commented Jul 1, 2025

Is there a test case?

Yes, but one of them was actually hit. I'm fixing this in #1336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants