lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 157 forks source link

Bug: Logical operation on `str` variables fail #2615

Closed kmr-srbh closed 1 month ago

kmr-srbh commented 3 months ago

1506 claimed to handle logical operations on strings, but as it turns out, things break. #2598 adds support for string literals, but the case of a string variable still fails with a segfault. The chief reason, as pointed out by @Shaikh-Ubaid is that the expr_value of the operands, in case of a string variable, result into a nullptr.

s_var1: str = "Hello"
s_var2: str = "LPython"

print(s_var1 or s_var2)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
Segmentation fault (core dumped)

The fix for this issue can help us to enable logical operations on string variables.