Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.invert returns Seq instead of Pair #6263

Closed
p6rt opened this issue May 23, 2017 · 4 comments
Closed

.invert returns Seq instead of Pair #6263

p6rt opened this issue May 23, 2017 · 4 comments

Comments

@p6rt
Copy link

p6rt commented May 23, 2017

Migrated from rt.perl.org#131349 (status was 'resolved')

Searchable as RT131349$

@p6rt
Copy link
Author

p6rt commented May 23, 2017

From @briandfoy

.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.

@p6rt
Copy link
Author

p6rt commented May 23, 2017

From @zoffixznet

On Tue, 23 May 2017 14​:36​:55 -0700, comdog wrote​:

.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] rakudo/rakudo@7ea0f66189
[2] https://github.com/perl6/roast/blob/6.c-errata/S02-types/pair.t#L330-L332
[3] Raku/roast@f4828aaf64
[4] Raku/doc@edd74317341a23

@p6rt
Copy link
Author

p6rt commented May 23, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 23, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant