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

Writablity of elements of slurpy params depends on given arguments #5939

Open
p6rt opened this issue Dec 29, 2016 · 4 comments
Open

Writablity of elements of slurpy params depends on given arguments #5939

p6rt opened this issue Dec 29, 2016 · 4 comments
Labels
regression Issue did not exist previously

Comments

@p6rt
Copy link

p6rt commented Dec 29, 2016

Migrated from rt.perl.org#130441 (status was 'open')

Searchable as RT130441$

@p6rt
Copy link
Author

p6rt commented Dec 29, 2016

From @AlexDaniel

Code​:
say (--**)(1,2,3,4,5)

Result (2015.12,2016.06)​:
(0 1 2 3 4)

Result (2016.11,HEAD)​:
Cannot resolve caller prefix​:<-->(Int); the following candidates
match the type but require mutable arguments​:
  (Mu​:D $a is rw)
  (Int​:D $a is rw)

The following do not match for other reasons​:
  (Bool $a is rw)
  (Mu​:U $a is rw)
  (Num​:D $a is rw)
  (Num​:U $a is rw)
  (int $a is rw)
  (num $a is rw --> num)
in block <unit> at /tmp/DOB7M3C38w line 1

While it is uncommon, I think the previous result is something one can sanely expect.

Bisectable points to rakudo/rakudo@de5d9e7

@p6rt
Copy link
Author

p6rt commented Dec 30, 2016

From @zoffixznet

There are two parts to this​:

1)​:

I'd expect the new behaviour of HyperWhatever and wouldn't think it's a bug. You get the same with regular Whatever.
 
  <Zoffix> m​: (--*)(1)
  <camelia> rakudo-moar 9fc616​: OUTPUT«Cannot resolve caller prefix​:<-->(Int); ...

And in fact, I can argue the 2015.12 version had a bug in it​:

  <Zoffix> committable6, 2015.12 my $x =1; say (--**)($x); say $x
  <committable6> Zoffix, ¦«2015.12»​: (0)␤1

The `--` does not affect the value of $x (while on HEAD it does). I can see either behaviour useful.

2)​:

HyperWhatever is just a glorified slurpy sub with `map`, so I played around with some code and found that the reason
hyperwhatevers in the past did not affect $x is because slurpies "detached", or "debinded", or whatever you
wanna call it, the given args and the contents of the slurpie had writable containers​:

  <Zoffix> committable6, 2015.12 sub { --@​_[0] }(1)
  <committable6> Zoffix, ¦«2015.12»​:
 
  <Zoffix> m​: sub { --@​_[0] }(1)
  <camelia> rakudo-moar 9fc616​: OUTPUT«Cannot resolve caller prefix​:<-->(Int); ...

On some level the above makes sense, however, that behavior changes depending on what *other* args get passed
to the slurpie. For example, if we add an extra Int, it still cries about non-writable thing for prefix​:<-->, but if the *extra*
arg is, for example, an array, then the *first* argument suddenly receives a writable container for itself.

  <Zoffix> m​: sub { --@​_[0] }(1, 1)
  <camelia> rakudo-moar 9fc616​: OUTPUT«Cannot resolve caller prefix​:<-->(Int); ...

  <Zoffix> m​: sub { --@​_[0] }(1, [1])
  <camelia> rakudo-moar 9fc616​: ( no output )

I recall there was a brief discussion about the above but I've no idea what the outcome was. The fact that it's inconsistent with regard to whether or not an arg is writable, based on type of other args, can be a tricky source of bugs and IMO should be made consistent.

Cheers,
ZZ

On Thu, 29 Dec 2016 08​:55​:08 -0800, alex.jakimenko@​gmail.com wrote​:

Code​:
say (--**)(1,2,3,4,5)

Result (2015.12,2016.06)​:
(0 1 2 3 4)

Result (2016.11,HEAD)​:
Cannot resolve caller prefix​:<-->(Int); the following candidates
match the type but require mutable arguments​:
(Mu​:D $a is rw)
(Int​:D $a is rw)

The following do not match for other reasons​:
(Bool $a is rw)
(Mu​:U $a is rw)
(Num​:D $a is rw)
(Num​:U $a is rw)
(int $a is rw)
(num $a is rw --> num)
in block <unit> at /tmp/DOB7M3C38w line 1

While it is uncommon, I think the previous result is something one can
sanely expect.

Bisectable points to
rakudo/rakudo@de5d9e7

@p6rt
Copy link
Author

p6rt commented Dec 30, 2016

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

@p6rt
Copy link
Author

p6rt commented Apr 16, 2017

From @zoffixznet

This seems very related​:

  <Zoffix_> m​: sub foo (*@​foo) { dd @​foo[1] = 42 }; foo <foo bar>; foo |<foo bar>;
  <camelia> rakudo-moar 88140b​: OUTPUT​: «42␤Cannot modify an immutable Str␤ in sub foo at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

It actually affects whether values in a created Map are mutable, *depending on how the Map was created*​:

  <Zoffix_> m​: dd Map.new(<foo bar>)<foo> = 42
  <camelia> rakudo-moar 88140b​: OUTPUT​: «Int <element> = 42␤»
  <Zoffix_> m​: dd Map.new(|<foo bar>)<foo> = 42
  <camelia> rakudo-moar 88140b​: OUTPUT​: «Cannot modify an immutable Str␤ in block <unit> at <tmp> line 1␤␤»

@p6rt p6rt added the regression Issue did not exist previously label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Issue did not exist previously
Projects
None yet
Development

No branches or pull requests

1 participant