Skip to content

Fix zero slice step #1879

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 2 commits into from
Jun 12, 2023
Merged

Fix zero slice step #1879

merged 2 commits into from
Jun 12, 2023

Conversation

kabra1110
Copy link
Collaborator

@kabra1110 kabra1110 commented Jun 4, 2023

Fixes #1833.
I have added the check for any slice step. This holds for strings and lists.
Are there places where zero step is allowed? (I don't think so.)

if (!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) {
throw SemanticError("slice indices must be integers or None", tmp->loc);
}
ASR::expr_t* val = ASRUtils::expr_value(ASRUtils::EXPR(tmp_step));
if (val != nullptr && ASR::down_cast<ASR::IntegerConstant_t>(val)->m_n == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also use is_value_constant, but this is also fine, I think.
LGTM!

Copy link
Collaborator

@czgdp1807 czgdp1807 left a comment

Choose a reason for hiding this comment

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

@czgdp1807 czgdp1807 enabled auto-merge (squash) June 12, 2023 04:15
@czgdp1807 czgdp1807 merged commit 13a386b into lcompilers:main Jun 12, 2023
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.

Edge case in slice step of Lists
3 participants