Skip to content

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Oct 21, 2025

3-arg call to builtins.range currently crashes mypyc if the 3rd argument's Expression isn't constant-foldable, with AssertionError with no message.

This PR fixes it.

I also got rid of some builder error which doesn't seem necessary but can put it back if it still serves a purpose even with the new generic fallback.

@BobTheBuidler BobTheBuidler changed the title [mypyc] fix: builder crashes on 3-arg range if step isnt foldable [mypyc] fix: builder crashes on 3-arg range(x, y, z) if step isnt foldable Oct 21, 2025
if len(expr.args) == 3:
step = builder.extract_int(expr.args[2])
assert step is not None
if step == 0:
Copy link
Contributor Author

@BobTheBuidler BobTheBuidler Oct 21, 2025

Choose a reason for hiding this comment

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

we no longer need to check this because we validate that it isn't None or 0 in our new if-check. 0 now falls back to the standard implementation where it fails normally

is_range_ref(expr.callee)
and (
len(expr.args) <= 2
or (len(expr.args) == 3 and builder.extract_int(expr.args[2]) is not None)
Copy link
Collaborator

@A5rocks A5rocks Oct 22, 2025

Choose a reason for hiding this comment

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

Huh, why did this fail with an assertion error? (I'm not used to mypyc...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeh, I'm realizing while re-reading this that it doesn't

I discovered this assert when working on #20100 and made this PR as an intermediate step which could be merged in before the full feature.

In hindsight I suppose this is no longer necessary, but I'll leave it open so maintainers can decide if we want to merge it before #20100

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.

2 participants