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

Scoping issue with unsignatured $_ #3226

Closed
p6rt opened this issue Sep 4, 2013 · 5 comments
Closed

Scoping issue with unsignatured $_ #3226

p6rt opened this issue Sep 4, 2013 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Sep 4, 2013

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

Searchable as RT119609$

@p6rt
Copy link
Author

p6rt commented Sep 4, 2013

From @lizmat

[23​:44​:41] <lizmat> r​: my %e; (%e{$_.WHICH} //= ($_ => 0)).value++ for <a b b c c c>; say %e.perl # scoping issue?
[23​:44​:43] <+camelia> rakudo 78ccd9​: OUTPUT«("Str|a" => Any => 1, "Str|b" => Any => 2, "Str|c" => Any => 3).hash␤»
[23​:44​:53] <lizmat> why are the pairs all Any?
[23​:46​:00] <lizmat> r​: my %e; for <a b b c c c> -> $k { (%e{$k.WHICH} //= ($k => 0)).value++}; say %e.perl # this seems to work
[23​:46​:02] <+camelia> rakudo 78ccd9​: OUTPUT«("Str|a" => "a" => 1, "Str|b" => "b" => 2, "Str|c" => "c" => 3).hash␤»
[23​:46​:19] <lizmat> feels like a rakudobug to me
[23​:46​:59] <FROGGS> r​: my %e; -> $_ { (%e{$_.WHICH} //= ($_ => 0)).value++ } for <a b b c c c>; say %e.perl # scoping issue?
[23​:47​:00] <+camelia> rakudo 78ccd9​: OUTPUT«("Str|a" => "a" => 1, "Str|b" => "b" => 2, "Str|c" => "c" => 3).hash␤»
[23​:47​:21] <jnthn> lizmat​: I'm tired, but yes, looks like...
[23​:47​:45] <lizmat> will use FROGGS++ quick fix
[23​:48​:01] <lizmat> and report as rakudobug

@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

From @diakopter

new behavior​:

15​:07 <diakopter> m​: my %e; (%e{$_.WHICH} //= ($_ => 0)).value++ for <a b b c c c>; say %e.perl │·······························
15​:07 <camelia> rakudo-moar 61d231​: OUTPUT«Cannot call postfix​:<++>(Int); none of these signatures match​:␤ (Mu​:D │·······························
  $a is rw)␤ (Mu​:U $a is rw)␤ (Int​:D $a is rw)␤ (int $a is rw)␤ (Bool​:U $a is rw)␤ │·······························
  (Bool​:D $a is rw)␤ (Num​:D $a is rw)␤ (Num​:U $a is rw)␤ (num …» │·······························

@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

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

@p6rt
Copy link
Author

p6rt commented May 2, 2016

From @smls

@​lizmat, @​FROGGS​:

Do you know how the original scoping issue reported in this RT, was fixed?

#​122709 and #​126569 suffer from similar scoping bugs involving $_ inside parens under a statement-modifier, and *haven't* been fixed yet.


@​matthew​:

That new behavior is to be expected.

It's a result of the fact that unlike hashes, pairs no longer automatically containerize their values.

And the ++ operator does not work on objects of type Int (those are immutable!), it only works on a Scalar container which happens to *contain* an Int.

For example​:

  say 0.VAR.^name; # Int
  say (a => 0).value.VAR.^name; # Int
 
  say (my $x = 0).VAR.^name; # Scalar
  say (a => (my $ = 0)).value.VAR.^name; # Scalar

In order to make your example work, you'd have to manually containerize the values of the keys you construct​:

  my %e; (%e{$_.WHICH} //= ($_ => (my $ = 0))).value++ for <a b b c c c>; say %e.perl
  # Output​:
  # {"Str|a" => (Any) => 3, "Str|b" => (Any) => 3, "Str|c" => (Any) => 3}

Or use a Hash of Arrays, instead of a Hash of Pairs.

@p6rt
Copy link
Author

p6rt commented May 2, 2016

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

@p6rt p6rt closed this as completed May 2, 2016
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