Skip to content

Commit ed556b4

Browse files
committed
add_error_for_slicing
1 parent 6dbb04a commit ed556b4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,9 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
16361636
AST::Slice_t *sl = AST::down_cast<AST::Slice_t>(x.m_slice);
16371637
if (sl->m_lower != nullptr) {
16381638
this->visit_expr(*sl->m_lower);
1639+
if (!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) {
1640+
throw SemanticError("slice indices must be integers or None", tmp->loc);
1641+
}
16391642
ai.m_left = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp));
16401643
}
16411644
if (sl->m_upper != nullptr) {
@@ -1647,6 +1650,9 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
16471650
}
16481651
if (sl->m_step != nullptr) {
16491652
this->visit_expr(*sl->m_step);
1653+
if (!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) {
1654+
throw SemanticError("slice indices must be integers or None", tmp->loc);
1655+
}
16501656
ai.m_step = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp));
16511657
}
16521658
if (ASR::is_a<ASR::List_t>(*type)) {

0 commit comments

Comments
 (0)