rakudo / rakudo

🦋 Rakudo – Raku on MoarVM, JVM, and JS
https://rakudo.org/
Artistic License 2.0
1.72k stars 373 forks source link

@a[-1;0]:exists returns True #2929

Open HarmtH opened 5 years ago

HarmtH commented 5 years ago

The Problem

> my @a; my $neg=-1; say @a[$neg;0]:exists
True

Expected Behavior

It returns False

Environment

lizmat commented 5 years ago

Fixed with https://github.com/rakudo/rakudo/commit/ca7408e9fa , tests added with https://github.com/perl6/roast/commit/4e732c620b

HarmtH commented 5 years ago

I was thinking a bit about this issue and about fix https://github.com/rakudo/rakudo/commit/ca7408e9fa

Wouldn't the array-of-array notation still be broken?

my @a; my $neg=-1; say @a[$neg][0]:exists
True

I think the real issue is Failures 'exist'. Maybe Failures should behave more like Nil. As a Failure is a Nil, that would also make sense. Although I don't know what the language specs say about this.

Failure is a Nil is a Cool is an Any is a Mu

> Failure.new[0]:exists
True
> Nil.new[0]:exists
False
> Cool.new[0]:exists
True
> Any.new[0]:exists
True
> Mu.new[0]:exists
Type check failed in binding to parameter '<anon>'; expected Any but got Mu (Mu.new)
  in block <unit> at <unknown file> line 1