Following #256 , the type checker does not quite elegantly deal with the fact that a Range is also a collection of integers.
Though the converse is not true, of course.
I won't fix it in that PR quite yet.
How to Reproduce
def f() -> Range => 0 .. 2 .. 1
for x in f() do
print(x)
With the following error:
Error: [error | type] Unifying type: Expected a '{`x`}', was a 'Range'
--> path/to/file:3:5
3 | for x in f() do
^
4 | print(x)
Iterating directly over a range does appear to work, however:
for x in 0 .. 2 .. 1 do
print(x)
So the type checker seems to make an exception there, though it shouldn't.
This is because currently it doesn't actual treat the above as a Range type at all.
It should deal with the above and that situation in an identical manner.
Expected behavior
It should work.
Perhaps in future the type checker should instead check for iterables.
One can iterate over a range, but not a slice for instance.
The way collections have been implemented has been somewhat ad-hoc anyway.
Description of Bug
Following #256 , the type checker does not quite elegantly deal with the fact that a Range is also a collection of integers. Though the converse is not true, of course. I won't fix it in that PR quite yet.
How to Reproduce
With the following error:
Iterating directly over a range does appear to work, however:
So the type checker seems to make an exception there, though it shouldn't. This is because currently it doesn't actual treat the above as a
Range
type at all. It should deal with the above and that situation in an identical manner.Expected behavior
It should work. Perhaps in future the type checker should instead check for iterables. One can iterate over a range, but not a slice for instance. The way collections have been implemented has been somewhat ad-hoc anyway.