lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.5k stars 158 forks source link

Improvement: Comparison on dissimilar types can be improved #2593

Open kmr-srbh opened 6 months ago

kmr-srbh commented 6 months ago

Comparing dissimilar types throws a semantic error stating type mismatch.

Checking equality

integer: i32 = 1
integer_list: list[i32] = [1, 2, 3, 4, 5]
print(integer == integer_list)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
semantic error: Type mismatch in comparison operator, the types must be compatible
 --> ./examples/example.py:5:7
  |
5 | print(integer == integer_list)
  |       ^^^^^^^    ^^^^^^^^^^^^ type mismatch ('i32' and 'list[i32]')

Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.

Checking inequality

integer: i32 = 1
integer_list: list[i32] = [1, 2, 3, 4, 5]
print(integer != integer_list)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
semantic error: Type mismatch in comparison operator, the types must be compatible
 --> ./examples/example.py:5:7
  |
5 | print(integer != integer_list)
  |       ^^^^^^^    ^^^^^^^^^^^^ type mismatch ('i32' and 'list[i32]')

Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.

Similar error is thrown for other operators.