Skip Menu |
Report information
Id: 131349
Status: resolved
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: comdog <brian.d.foy [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: rakudobug [...] perl.org
From: brian d foy <brian.d.foy [...] gmail.com>
Date: Tue, 23 May 2017 17:36:10 -0400
Subject: .invert returns Seq instead of Pair
Download (untitled) / with headers
text/plain 973b
.invert doesn't do what it says on the tin. From https://docs.perl6.org/type/Pair#method_invert my Pair $p1 = (6 => 'Perl'); say $p1.invert; # OUTPUT: «Perl => 6␤» say $p1.invert.WHAT; # OUTPUT: «(Pair)␤» my Pair $p2 = ('Perl' => (5, 6)); say $p2.invert; # OUTPUT: «(5 => Perl 6 => Perl)␤» say $p2.invert.WHAT; # OUTPUT: «(List)␤» my Pair $p3 = ('Perl' => { cool => 'language'}); say $p3.invert; # OUTPUT: «{cool => language => Perl}␤» say $p3.invert.WHAT; # OUTPUT: «(Hash)␤» I get sequences instead: (Perl => 6) (Seq) (5 => Perl 6 => Perl) (Seq) ((cool => language) => Perl) (Seq) % perl6 -v This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda implementing Perl 6.c.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.8k
On Tue, 23 May 2017 14:36:55 -0700, comdog wrote: Show quoted text
> .invert doesn't do what it says on the tin. From > https://docs.perl6.org/type/Pair#method_invert > > my Pair $p1 = (6 => 'Perl'); > say $p1.invert; # OUTPUT: «Perl => 6␤» > say $p1.invert.WHAT; # OUTPUT: «(Pair)␤» > > my Pair $p2 = ('Perl' => (5, 6)); > say $p2.invert; # OUTPUT: «(5 => > Perl 6 => Perl)␤» > say $p2.invert.WHAT; # OUTPUT: «(List)␤» > > my Pair $p3 = ('Perl' => { cool => 'language'}); > say $p3.invert; # OUTPUT: «{cool > => language => Perl}␤» > say $p3.invert.WHAT; # OUTPUT: «(Hash)␤» > > I get sequences instead: > > (Perl => 6) > (Seq) > (5 => Perl 6 => Perl) > (Seq) > ((cool => language) => Perl) > (Seq) > > % perl6 -v > This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda > implementing Perl 6.c.
Thank you for the report. This issue is now resolved. While it was fixed accidentally[^1], the old behaviour was inconsistent with the .invert on the other types, and looking at the [^2] spec tests for it, it appears due to faulty tests, they were passing for the wrong reason. The tests index `[0]` the return value without checking what they're indexing, so the returned Pair was simply treated as a 1-item list automatically. I added[^3] more roast tests to spec Pair.invert as always returning a Seq and fixed[^4] the docs to reflect the correct behaviour. [1] https://github.com/rakudo/rakudo/commit/7ea0f66189 [2] https://github.com/perl6/roast/blob/6.c-errata/S02-types/pair.t#L330-L332 [3] https://github.com/perl6/roast/commit/f4828aaf64 [4] https://github.com/perl6/doc/commit/edd74317341a23


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org