From a3b62cba31c428bd7566dd81fc2b86088fb45e3e Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Fri, 28 Nov 2025 21:40:40 +0000 Subject: [PATCH 1/5] Add semantic error test for assignment to literal --- tests/errors/reproduce_bug_01.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/errors/reproduce_bug_01.py 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 From 8f557cbcfa9bf3dcaede02799b8011ff70304abb Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Fri, 28 Nov 2025 22:05:33 +0000 Subject: [PATCH 2/5] Fix: prevent assignment to literal (semantic error) --- src/lpython/semantics/python_ast_to_asr.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 4d116cfce7..45dd778691 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -5654,6 +5654,11 @@ 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])) { + 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])) { From 7afdb32591dfecee78c03e5b91408a428f73074c Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Fri, 28 Nov 2025 22:47:30 +0000 Subject: [PATCH 3/5] Remove forbidden iostream header --- src/lpython/semantics/python_ast_to_asr.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 45dd778691..ade5aec269 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 From 94fabb0765e46b6c213fb9974ef13c3bd8d34414 Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Fri, 28 Nov 2025 23:09:38 +0000 Subject: [PATCH 4/5] Fix: Use correct AST types for literal assignment check --- src/lpython/semantics/python_ast_to_asr.cpp | 9 ++++++++- tests/errors/reproduce_bug_01.out | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/errors/reproduce_bug_01.out diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index ade5aec269..d713de7c73 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -5653,7 +5653,14 @@ class BodyVisitor : public CommonVisitor { assign_value = ASRUtils::EXPR(tmp); } for (size_t i=0; i(*x.m_targets[i]) || + if (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]) || AST::is_a(*x.m_targets[i])) { throw SemanticError("SyntaxError: cannot assign to literal", x.m_targets[i]->base.loc); 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. From 85d32c6fa38cde30e35229903e2058c92faf7ad8 Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Sat, 29 Nov 2025 08:38:04 +0000 Subject: [PATCH 5/5] CI: re-run tests