← 输入框|github.com|刷新
Skip to content

Using list() on a list variable does not work #2667

Open

Description

@ubaidsk
% cat examples/expr2.py   
from lpython import i32

a: list[i32]
a = [2, 3]
b: list[i32]
b = list(a)
print(b)
% python examples/expr2.py
[2, 3]
% lpython examples/expr2.py
semantic error: Type mismatch in assignment, the types must be compatible
 --> examples/expr2.py:6:1
  |
6 | b = list(a)
  | ^   ^^^^^^^ type mismatch ('list[i32]' and 'list[str]')


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

Activity

  1. kmr-srbh commented on Apr 26, 2024

    @kmr-srbh
    Contributor

    I have a working fix ready for this. I wish to discuss some design decisions before pushing the changes.

    We essentially need generics to fully achieve this. The error in the above example stated list[str] because that is the only implementation we currently have for list() inside lpython_builtin.py. I have written some implementations for list of integers and floats, but we cannot handle arbitrary nesting this way. For now, we may handle some nesting by hand, like list[list[i32]]. Although it is not a good idea, it will help us to test methods like dict.keys and dict.values more clearly. Currently tests for both these methods check for the length of the returned list.

    @Shaikh-Ubaid @certik @czgdp1807 What is your take on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions