◐ Shell
clean mode source ↗

Add semantic error test for assignment to literal by amritamishra01 · Pull Request #2871 · lcompilers/lpython

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.