erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.61k stars 53 forks source link

TypeError: Str or List(Str, _: Nat) does not implement Iterable(Str) #512

Closed nanakura closed 1 month ago

nanakura commented 1 month ago

Describe the bug?

List(Str) Union types does not implement the Iterable trait

Reproducible code

os = pyimport "os"

d = os.getcwd!()
for! os.walk!(d), [root, dirs, files] =>
  print! root, dirs, files
  filtered_d = dirs.iter().filter(i -> i == "").to_list()
  print! filtered_d 

Expected result

compile success

Actual result

🚫 Error[#2388]: File test3.er, line 6, <module>::<lambda_5>::filtered_d

6 │   filtered_d = dirs.iter().filter(i -> i == "").to_list()
  ·                ----

TypeError: Str or List(Str, _: Nat) does not implement Iterable(Str)

Additional context

D:\workspace\erg\demo1>erg --version Erg 0.6.36

Erg version

0.6.36

Python version

Python3.11

OS

Windows 11