Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

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

Open p6rt opened 7 years ago

p6rt commented 7 years ago

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

Searchable as RT130441$

p6rt commented 7 years ago

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 \ at /tmp/DOB7M3C38w line 1

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

Bisectable points to https://github.com/rakudo/rakudo/commit/de5d9e70cbfe678d2371d284e9384f53aba1eb94

p6rt commented 7 years ago

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.  
  \ m​: (--*)(1)   \ rakudo-moar 9fc616​: OUTPUT«Cannot resolve caller prefix​:\<-->(Int); ...

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

  \ committable6, 2015.12 my $x =1; say (--**)($x); say $x   \ 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​:

  \ committable6, 2015.12 sub { --@​_[0] }(1)   \ Zoffix, ¦«2015.12»​:  
  \ m​: sub { --@​_[0] }(1)   \ 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.

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

  \ m​: sub { --@​_[0] }(1, [1])   \ 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 \ at /tmp/DOB7M3C38w line 1

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

Bisectable points to https://github.com/rakudo/rakudo/commit/de5d9e70cbfe678d2371d284e9384f53aba1eb94

p6rt commented 7 years ago

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

p6rt commented 7 years ago

From @zoffixznet

This seems very related​:

  \<Zoffix_> m​: sub foo (*@​foo) { dd @​foo[1] = 42 }; foo \; foo |\;   \ rakudo-moar 88140b​: OUTPUT​: «42␤Cannot modify an immutable Str␤ in sub foo at \ line 1␤ in block \ at \ 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(\)\ = 42   \ rakudo-moar 88140b​: OUTPUT​: «Int \ = 42␤»   \<Zoffix_> m​: dd Map.new(|\)\ = 42   \ rakudo-moar 88140b​: OUTPUT​: «Cannot modify an immutable Str␤ in block \ at \ line 1␤␤»