Skip to content

Commit 94fabb0

Browse files
Fix: Use correct AST types for literal assignment check
1 parent 7afdb32 commit 94fabb0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5653,7 +5653,14 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
56535653
assign_value = ASRUtils::EXPR(tmp);
56545654
}
56555655
for (size_t i=0; i<x.n_targets; i++) {
5656-
if (AST::is_a<AST::Constant_t>(*x.m_targets[i]) ||
5656+
if (AST::is_a<AST::ConstantStr_t>(*x.m_targets[i]) ||
5657+
AST::is_a<AST::ConstantInt_t>(*x.m_targets[i]) ||
5658+
AST::is_a<AST::ConstantBool_t>(*x.m_targets[i]) ||
5659+
AST::is_a<AST::ConstantFloat_t>(*x.m_targets[i]) ||
5660+
AST::is_a<AST::ConstantComplex_t>(*x.m_targets[i]) ||
5661+
AST::is_a<AST::ConstantEllipsis_t>(*x.m_targets[i]) ||
5662+
AST::is_a<AST::ConstantNone_t>(*x.m_targets[i]) ||
5663+
AST::is_a<AST::ConstantBytes_t>(*x.m_targets[i]) ||
56575664
AST::is_a<AST::Set_t>(*x.m_targets[i]) ||
56585665
AST::is_a<AST::Dict_t>(*x.m_targets[i])) {
56595666
throw SemanticError("SyntaxError: cannot assign to literal", x.m_targets[i]->base.loc);

tests/errors/reproduce_bug_01.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
semantic error: SyntaxError: cannot assign to literal
2+
--> tests/errors/reproduce_bug_01.py:2:1
3+
|
4+
2 | 'a' = 1
5+
| ^^^ 
6+
7+
8+
Note: Please report unclear, confusing or incorrect messages as bugs at
9+
https://github.com/lfortran/lfortran/issues.

0 commit comments

Comments
 (0)