On Wed, 08 Jul 2015 05:53:44 -0700, liu...@360.cn wrote:
> http://irclog.perlgeek.de/perl6/2015-07-08#i_10865609
> 
> my Int @a = 1 .. Inf;
> @a[*-1], @a[*-Inf], @a[Inf];
> 
> Cannot coerce Inf or NaN to an Int

Closing this, as the `@a[*-1]` mentioned in the IRC log now rightly complains 
about lazy lists. (Added a vaguish test for it in 
https://github.com/perl6/roast/commit/ada48a6538 )

The fact that `my Int @a = 1..Inf;` or even `m: my Int @a = lazy 1, NaN, Int;` 
does not throw is not a bug. The `@` sigil is mostly-eager and it does not 
reify stuff that .is-lazy on assignment, so *it has no idea* some of the 
elements are not of the appropriate type and would need to be able to time 
travel to throw there and then.

If you do reify the array, then throwage does happen when you reach 
inappropriate type:

    m: my Int @a = lazy 1, NaN, Int; .say for @a
    rakudo-moar 9f0b12: OUTPUT: «1␤Type check failed in assignment to @a; 
expected Int but got Num (NaN)␤  in block <unit> at <tmp> line 1␤␤

Lastly, some of the other errors mentioned in the IRC log aren't due to Inf in 
the array, but due to trying to use a non-Intifying thing as an Array index:

    <ZoffixW> m: [][Inf]
    <camelia> rakudo-moar 9f0b12: OUTPUT: «Cannot coerce Inf to an Int␤  in 
block <unit> at <tmp> line 1␤␤Actually thrown at:␤  in block <unit> at <tmp> 
line 1␤␤»
    <ZoffixW> m: [][i]
    <camelia> rakudo-moar 9f0b12: OUTPUT: «Can not convert 0+1i to Int: 
imaginary part not zero␤  in block <unit> at <tmp> line 1␤␤Actually thrown at:␤ 
 in block <unit> at <tmp> line 1␤␤»

Reply via email to