Skip to content

Commit ea0d11b

Browse files
author
whitequark
committedJun 26, 2015
Allow also passing iterables to lists.
1 parent e07057c commit ea0d11b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
 

Diff for: ‎artiq/py2llvm/typing.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -804,15 +804,28 @@ def diagnose(valid_forms):
804804
elif builtins.is_builtin(typ, "class list"):
805805
valid_forms = lambda: [
806806
valid_form("list() -> list(elt='a)"),
807-
# TODO: add this form when adding iterators
808-
# valid_form("list(x) -> list(elt='a)")
807+
valid_form("list(x:'a) -> list(elt='b) where 'a is iterable")
809808
]
810809

811810
self._unify(node.type, builtins.TList(),
812811
node.loc, None)
813812

814813
if len(node.args) == 0 and len(node.keywords) == 0:
815814
pass # []
815+
elif len(node.args) == 1 and len(node.keywords) == 0:
816+
arg, = node.args
817+
818+
if builtins.is_iterable(arg.type):
819+
pass
820+
else:
821+
note = diagnostic.Diagnostic("note",
822+
"this expression has type {type}",
823+
{"type": types.TypePrinter().name(arg.type)},
824+
arg.loc)
825+
diag = diagnostic.Diagnostic("error",
826+
"the argument of list() must be of an iterable type", {},
827+
node.func.loc, notes=[note])
828+
self.engine.process(diag)
816829
else:
817830
diagnose(valid_forms())
818831
elif builtins.is_builtin(typ, "function range"):
@@ -854,7 +867,7 @@ def diagnose(valid_forms):
854867
if len(node.args) == 1 and len(node.keywords) == 0:
855868
arg, = node.args
856869

857-
if builtins.is_list(arg.type) or builtins.is_range(arg.type):
870+
if builtins.is_iterable(arg.type):
858871
pass
859872
else:
860873
note = diagnostic.Diagnostic("note",

Diff for: ‎lit-test/py2llvm/typing/error_builtin_calls.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
# CHECK-L: ${LINE:+1}: error: the argument of len() must be of an iterable type
99
len(1)
1010

11+
# CHECK-L: ${LINE:+1}: error: the argument of list() must be of an iterable type
12+
list(1)
13+
1114
# CHECK-L: ${LINE:+1}: error: an argument of range() must be of a numeric type
1215
range([])

0 commit comments

Comments
 (0)
Please sign in to comment.