Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <memory>
Expand Down Expand Up @@ -5654,6 +5653,18 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
assign_value = ASRUtils::EXPR(tmp);
}
for (size_t i=0; i<x.n_targets; i++) {
if (AST::is_a<AST::ConstantStr_t>(*x.m_targets[i]) ||
AST::is_a<AST::ConstantInt_t>(*x.m_targets[i]) ||
AST::is_a<AST::ConstantBool_t>(*x.m_targets[i]) ||
AST::is_a<AST::ConstantFloat_t>(*x.m_targets[i]) ||
AST::is_a<AST::ConstantComplex_t>(*x.m_targets[i]) ||
AST::is_a<AST::ConstantEllipsis_t>(*x.m_targets[i]) ||
AST::is_a<AST::ConstantNone_t>(*x.m_targets[i]) ||
AST::is_a<AST::ConstantBytes_t>(*x.m_targets[i]) ||
AST::is_a<AST::Set_t>(*x.m_targets[i]) ||
AST::is_a<AST::Dict_t>(*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<AST::Subscript_t>(*x.m_targets[i])) {
Expand Down
9 changes: 9 additions & 0 deletions tests/errors/reproduce_bug_01.out
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions tests/errors/reproduce_bug_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TEST EXPECTS SEMANTIC ERROR
'a' = 1
Loading