lcompilers / lpython

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

Wrong type for logical comparison in C backend #2708

Open hankluo6 opened 1 month ago

hankluo6 commented 1 month ago
def main0():
    s_var1: str = "Hello"
    s_var2: str = "LPython"

    print(s_var1 or s_var2)

(lp) hank@MacBook-Pro lpython % ./src/bin/lpython test.py --backend=c
expr2__tmp__generated__.c: In function ‘main0’:
expr2__tmp__generated__.c:21:14: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
   21 |     printf("%s\n", s_var1 || s_var2);
      |             ~^     ~~~~~~~~~~~~~~~~
      |              |            |
      |              char *       int
      |             %d
Segmentation fault

The problem might be because the type for BoolOp is character rather than int.