Add semantic error test for assignment to literal #2871
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request adds a new semantic error test to ensure LPython correctly rejects assignments to literal values.
✔ What this PR does
Adds a new test: tests/errors/reproduce_bug_01.py
The test checks that assigning to a literal (e.g., 'a' = 1) raises the expected SyntaxError: cannot assign to literal.
Adds the corresponding .out file with the correct error output.
Updates python_ast_to_asr.cpp by adding a semantic check:
Detects assignment targets that are literals (Constant, Set, Dict)
Throws a SemanticError with a clear and correct message.
✔ Why this is important
Python does not allow assignment to literal values.
This PR ensures LPython’s semantic analysis matches Python’s behavior and provides a clear error message.
✔ How it was tested
Ran the single test using:
python3 run_tests.py -t tests/errors/reproduce_bug_01.py
Test passes successfully.