Skip to content
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

Fix panic when filling up types vector during unpacking #14006

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

dhruvmanila
Copy link
Member

Summary

This PR fixes a panic which can occur in an unpack assignment when:

  • (number of target expressions) - (number of tuple types) > 2
  • There's a starred expression

The reason being that the insert panics because the index is greater than the length.

This is an error case and so practically it should occur very rarely. The solution is to resize the types vector to match the number of expressions and then insert the starred expression type.

Test Plan

Add a new test case.

@dhruvmanila dhruvmanila added the red-knot Multi-file analysis & type inference label Oct 30, 2024
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

Nice!

@dhruvmanila dhruvmanila enabled auto-merge (squash) October 30, 2024 19:10
@dhruvmanila dhruvmanila merged commit 2629527 into main Oct 30, 2024
17 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/fix-unpack-panic branch October 30, 2024 19:13
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants