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

is rw on anon parameter causes "inconsistent bind result" error #6366

Closed
p6rt opened this issue Jun 28, 2017 · 7 comments
Closed

is rw on anon parameter causes "inconsistent bind result" error #6366

p6rt opened this issue Jun 28, 2017 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Jun 28, 2017

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

Searchable as RT131673$

@p6rt
Copy link
Author

p6rt commented Jun 28, 2017

From @zoffixznet

Works as expected​:
  23​:03 m​: sub ($x is rw) {}(42)
  camelia rakudo-moar 2a8d1e​: OUTPUT​: «Parameter '$x' expected a writable container, but got Int valueâ�¤ in sub at <tmp> line 1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»

Doesn't​:
  23​:04 m​: sub ($ is rw) {}(42)
  23​:04 camelia rakudo-moar 2a8d1e​: OUTPUT​: «Internal error​: inconsistent bind resultâ�¤ in sub at <tmp> line 1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»

@p6rt
Copy link
Author

p6rt commented Jun 29, 2017

From @lizmat

Shouldn’t​:

  sub ($ is rw) { }

be a compile-time error? I mean, there is no way to actually assign to the anonymous variable, is there? So there is no point in the “is rw”. So most likely indicates a typo on the user side.

On 29 Jun 2017, at 01​:05, Zoffix Znet (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Zoffix Znet
# Please include the string​: [perl #​131673]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=131673 >

Works as expected​:
23​:03 m​: sub ($x is rw) {}(42)
camelia rakudo-moar 2a8d1e​: OUTPUT​: «Parameter '$x' expected a writable container, but got Int valueâ�¤ in sub at <tmp> line 1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»

Doesn't​:
23​:04 m​: sub ($ is rw) {}(42)
23​:04 camelia rakudo-moar 2a8d1e​: OUTPUT​: «Internal error​: inconsistent bind resultâ�¤ in sub at <tmp> line 1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»

@p6rt
Copy link
Author

p6rt commented Jun 29, 2017

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

@p6rt
Copy link
Author

p6rt commented Jun 29, 2017

From @zoffixznet

On Thu, 29 Jun 2017 00​:45​:02 -0700, elizabeth wrote​:

Shouldn’t​:

sub ($ is rw) { }

be a compile-time error? I mean, there is no way to actually assign
to the anonymous variable, is there? So there is no point in the “is
rw”. So most likely indicates a typo on the user side.

Feels a bit of an overreach to make that judgement. What if I don't want to assign anything to it, but just want to force the user of my sub to use a writable container? There might be a usecase for wanting that. While typoing a variable name would be easily detected via another error, when the user tries to use the variable in the body.

For example, I can multi-dispatch based on that and it works right​:

  <Zoffix__> m​: multi foo ($) { say 'here' }; multi foo ($ is rw) { say 'there' }; foo 42
  <camelia> rakudo-moar 2a8d1e​: OUTPUT​: «here␤»
  <Zoffix__> m​: multi foo ($) { say 'here' }; multi foo ($ is rw) { say 'there' }; foo $ = 42
  <camelia> rakudo-moar 2a8d1e​: OUTPUT​: «there␤»

Or I want to unpack only iterables with writable containers, while grabbing all but one item, which actually seems to have another bug in it in that the anon doesn't force rw at all​:

  <Zoffix__> m​: sub foo (@​ ($x is rw, |c)) { say c }; foo (42, 42)
  <camelia> rakudo-moar 2a8d1e​: OUTPUT​: «Parameter '$x' expected a writable container, but got Int value␤ in sub foo at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»
  <Zoffix__> m​: sub foo (@​ ($ is rw, |c)) { say c }; foo (42, 42)
  <camelia> rakudo-moar 2a8d1e​: OUTPUT​: «\(42)␤»

@p6rt
Copy link
Author

p6rt commented Jun 29, 2017

From @zoffixznet

On Thu, 29 Jun 2017 03​:13​:07 -0700, cpan@​zoffix.com wrote​:

On Thu, 29 Jun 2017 00​:45​:02 -0700, elizabeth wrote​:

Shouldn’t​:

sub ($ is rw) { }

be a compile-time error? I mean, there is no way to actually assign
to the anonymous variable, is there? So there is no point in the “is
rw”. So most likely indicates a typo on the user side.

Here's a less convoluted example for the last usecase. Taking an iterable with 2 rw containers, while not necessarily wanting to assign each of the items into their own variables. I'd expect the first example to error out just like the last example instead of accepting the values (or dying with inconsistent bind error)​:

  <Zoffix__> m​: sub foo (@​a ($ is rw, $ is rw)) { $_++ for @​a }; my @​a := 42, 42; foo @​a; dd @​a
  <camelia> rakudo-moar 2a8d1e​: OUTPUT​: «Cannot resolve caller postfix​:<++>(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​:D $a is rw)␤ (Bool​:U $a is …»
  <Zoffix__> m​: sub foo (@​a ($ is rw, $ is rw)) { $_++ for @​a }; my @​a = 42, 42; foo @​a; dd @​a
  <camelia> rakudo-moar 2a8d1e​: OUTPUT​: «Array @​a = [43, 43]␤»
  <Zoffix__> m​: sub foo (@​a ($z is rw, $zz is rw)) { $_++ for @​a }; my @​a := 42, 42; foo @​a; dd @​a
  <camelia> rakudo-moar 2a8d1e​: OUTPUT​: «Parameter '$z' expected a writable container, but got Int value␤ in sub foo at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

@p6rt
Copy link
Author

p6rt commented Jul 14, 2017

From @jnthn

On Wed, 28 Jun 2017 16​:05​:50 -0700, cpan@​zoffix.com wrote​:

Works as expected​:
23​:03 m​: sub ($x is rw) {}(42)
camelia rakudo-moar 2a8d1e​: OUTPUT​: «Parameter '$x' expected
a writable container, but got Int value� in sub at <tmp> line 1�
in block <unit> at <tmp> line 1��»

Doesn't​:
23​:04 m​: sub ($ is rw) {}(42)
23​:04 camelia rakudo-moar 2a8d1e​: OUTPUT​: «Internal error​:
inconsistent bind result� in sub at <tmp> line 1� in block
<unit> at <tmp> line 1��»

Fixed and tested in S06-traits/is-rw.t.

@p6rt p6rt closed this as completed Jul 14, 2017
@p6rt
Copy link
Author

p6rt commented Jul 14, 2017

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

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