lcompilers / lpython

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

Bug: Global declaration of `set` fails #2604

Closed kmr-srbh closed 6 months ago

kmr-srbh commented 6 months ago

Declaring a set in the global scope fails. This however is not the case with a local scope like a function.

s: set[str] = {"a", "b", "c", "a"}
s.add("d")
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
code generation error: Variable type not supported 6
 --> ./examples/example.py:1:1
  |
1 | s: set[str] = {"a", "b", "c", "a"}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

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

As it turns out, the error message is not clear too.

Shaikh-Ubaid commented 6 months ago

In the code example shared in the issue description, you need not import set from the lpython module as set is predefined in cpython. You also need not import i32 as it is unused. So the example in the issue description can be simplified to:

s: set[str] = {"a", "b", "c", "a"}
s.add("d")