Assignment with list patterns does not work. #459

Open
opened 2024-07-16 11:35:42 +08:00 by lyken · 0 comments
Collaborator
@extern
def output_int32(x: int32):
    ...

def run() -> int32:
    x, [y, z] = 1, [2, 3]
    output_int32(x)
    output_int32(y)
    output_int32(z)
    return 0

Gives the error:

1 error(s) occurred during top level analysis.
=========== ERROR 1/1 ============
type error at identifier `y` (cannot get type of y) at src/_test.py:6:9
==================================

Note that with tuples x, (y, z) = 1, (2, 3), it does work.

This is not easy to support - the codegen part could be very complicated - R.H.S. could contain a list whose length cannot be determined at compile time, this might need an LLVM for loop to assign the elements of the input list to different vars on L.H.S + assertion on the input list's length.

```python @extern def output_int32(x: int32): ... def run() -> int32: x, [y, z] = 1, [2, 3] output_int32(x) output_int32(y) output_int32(z) return 0 ``` Gives the error: ``` 1 error(s) occurred during top level analysis. =========== ERROR 1/1 ============ type error at identifier `y` (cannot get type of y) at src/_test.py:6:9 ================================== ``` Note that with tuples `x, (y, z) = 1, (2, 3)`, it does work. This is not easy to support - the codegen part could be very complicated - R.H.S. could contain a list whose length cannot be determined at compile time, this might need an LLVM for loop to assign the elements of the input list to different vars on L.H.S + assertion on the input list's length.
lyken added the
low-priority
label 2024-07-16 11:35:42 +08:00
lyken changed title from Assignment with list pattern matching does not work. to Assignment with list patterns does not work. 2024-07-16 11:35:54 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#459
No description provided.