forked from M-Labs/artiq
1
0
Fork 0

Inferencer: range() does not accept a float argument.

This commit is contained in:
whitequark 2015-08-10 17:06:55 +03:00
parent f53a5ff202
commit b28a874274
1 changed files with 9 additions and 8 deletions

View File

@ -596,7 +596,7 @@ class Inferencer(algorithm.Visitor):
self._unify(arg.type, range_tvar, self._unify(arg.type, range_tvar,
arg.loc, None) arg.loc, None)
if builtins.is_numeric(arg.type): if builtins.is_int(arg.type):
pass pass
elif types.is_var(arg.type): elif types.is_var(arg.type):
pass # undetermined yet pass # undetermined yet
@ -606,7 +606,7 @@ class Inferencer(algorithm.Visitor):
{"type": types.TypePrinter().name(arg.type)}, {"type": types.TypePrinter().name(arg.type)},
arg.loc) arg.loc)
diag = diagnostic.Diagnostic("error", diag = diagnostic.Diagnostic("error",
"an argument of range() must be of a numeric type", {}, "an argument of range() must be of an integer type", {},
node.func.loc, notes=[note]) node.func.loc, notes=[note])
self.engine.process(diag) self.engine.process(diag)
else: else:
@ -616,15 +616,16 @@ class Inferencer(algorithm.Visitor):
valid_form("len(x:'a) -> int(width='b) where 'a is iterable"), valid_form("len(x:'a) -> int(width='b) where 'a is iterable"),
] ]
# TODO: should be ssize_t-sized
self._unify(node.type, builtins.TInt(types.TValue(32)),
node.loc, None)
if len(node.args) == 1 and len(node.keywords) == 0: if len(node.args) == 1 and len(node.keywords) == 0:
arg, = node.args arg, = node.args
if builtins.is_iterable(arg.type): if builtins.is_range(arg.type):
pass self._unify(node.type, builtins.get_iterable_elt(arg.type),
node.loc, None)
elif builtins.is_list(arg.type):
# TODO: should be ssize_t-sized
self._unify(node.type, builtins.TInt(types.TValue(32)),
node.loc, None)
elif types.is_var(arg.type): elif types.is_var(arg.type):
pass # undetermined yet pass # undetermined yet
else: else: