Uh oh!
There was an error while loading. Please reload this page.
Add semantic error test for assignment to literal - #2871
Conversation
amritamishra01
commented
Nov 29, 2025
Hi! I’ve applied all the requested review changes (removed debug prints, fixed headers, and used the precise AST node types). Linux, Windows, and WASM CI all pass successfully. ld: warning: object file was built for newer 'macOS' version (15.0) This warning gets captured in stderr and causes This failure is unrelated to the changes in this PR. Thank you! |
amritamishra01
commented
Dec 11, 2025
Update: Rebased on the latest main and all CI checks are now passing (18/18). I have verified the fix locally and confirmed the tests pass on the CI. This is ready for final review! |
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.