Skip to content

Commit

Permalink
add_error_for_slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
faze-geek committed Jun 16, 2022
1 parent 6dbb04a commit ed556b4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,9 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
AST::Slice_t *sl = AST::down_cast<AST::Slice_t>(x.m_slice);
if (sl->m_lower != nullptr) {
this->visit_expr(*sl->m_lower);
if (!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) {
throw SemanticError("slice indices must be integers or None", tmp->loc);
}
ai.m_left = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp));
}
if (sl->m_upper != nullptr) {
Expand All @@ -1647,6 +1650,9 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
}
if (sl->m_step != nullptr) {
this->visit_expr(*sl->m_step);
if (!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) {
throw SemanticError("slice indices must be integers or None", tmp->loc);
}
ai.m_step = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp));
}
if (ASR::is_a<ASR::List_t>(*type)) {
Expand Down

0 comments on commit ed556b4

Please sign in to comment.