diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 4d116cfce7..d713de7c73 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -5654,6 +5653,18 @@ class BodyVisitor : public CommonVisitor { assign_value = ASRUtils::EXPR(tmp); } for (size_t i=0; i(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i]) || + AST::is_a(*x.m_targets[i])) { + throw SemanticError("SyntaxError: cannot assign to literal", x.m_targets[i]->base.loc); + } tmp_value = assign_value; check_is_assign_to_input_param(x.m_targets[i]); if (AST::is_a(*x.m_targets[i])) { diff --git a/tests/errors/reproduce_bug_01.out b/tests/errors/reproduce_bug_01.out new file mode 100644 index 0000000000..1cb4c03f92 --- /dev/null +++ b/tests/errors/reproduce_bug_01.out @@ -0,0 +1,9 @@ +semantic error: SyntaxError: cannot assign to literal + --> tests/errors/reproduce_bug_01.py:2:1 + | +2 | 'a' = 1 + | ^^^  + + +Note: Please report unclear, confusing or incorrect messages as bugs at +https://github.com/lfortran/lfortran/issues. diff --git a/tests/errors/reproduce_bug_01.py b/tests/errors/reproduce_bug_01.py new file mode 100644 index 0000000000..de24edaa2a --- /dev/null +++ b/tests/errors/reproduce_bug_01.py @@ -0,0 +1,2 @@ +# TEST EXPECTS SEMANTIC ERROR +'a' = 1