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

postcircumfix:<( )> invocations get a Capture object, should just get the signature in Rakudo #2821

Closed
p6rt opened this issue Jul 7, 2012 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Jul 7, 2012

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

Searchable as RT114026$

@p6rt
Copy link
Author

p6rt commented Apr 27, 2012

From @gfldex

use v6;

sub somesub(){
  say "i haz a sub";
};

class Foo {
  has @​.a is rw;
  method add(&c){ @​.a.push(&c) }
  method postcircumfix​:<( )>($self​: |$c) {
  #since i stripped self into $self, the capture should be empty
  @​.a>>.(|$c)
  }
}

my $foo = Foo.new;
$foo.add(&somesub);

$foo();
#> Too many positional parameters passed; got 1 but expected 0
#> in sub somesub at empty_capture.p6​:3

@p6rt
Copy link
Author

p6rt commented Jul 7, 2012

From @masak

<quietfanatic> rn​: class A { method postcircumfix​:<( )> (A​:U​:) { say 3 } }; A()
<p6eval> rakudo 57eaaa​: OUTPUT«Too many positional parameters passed;
got 2 but expected 1␤ in method postcircumfix​:<( )> [...]
<p6eval> ..niecza v19-12-gf36d743​: OUTPUT«3␤»
<quietfanatic> niecza++
<pmichaud> r​: class XYZ { method postcircumfix​:<( )>(XYZ​:U​: $x) { say
3 } }; XYZ(0) # checking
<p6eval> rakudo 57eaaa​: OUTPUT«3␤»
<pmichaud> r​: class XYZ { method postcircumfix​:<( )>(XYZ​:U​: $x) { say
3 } }; XYZ() # checking
<p6eval> rakudo 57eaaa​: OUTPUT«3␤»
<pmichaud> hmmmm
<pmichaud> r​: class XYZ { method postcircumfix​:<( )>(XYZ​:U​: $x) { say
3 } }; XYZ(3,4,5) # checking
<p6eval> rakudo 57eaaa​: OUTPUT«3␤»
<pmichaud> I bet Rakudo is always expecting a Capture of the arguments there.
<quietfanatic> huh
<pmichaud> r​: class XYZ { method postcircumfix​:<( )>(XYZ​:U​: $x) { say
$x.WHAT } }; XYZ(3,4,5) # checking
<p6eval> rakudo 57eaaa​: OUTPUT«Capture()␤»
<pmichaud> *ding*
<quietfanatic> Where does that capture come from?
<pmichaud> it's the capture formed by the arglist to the .( ) call
<quietfanatic> oh, so
<quietfanatic> r​: class XYZ { method postcircumfix​:<( )>(XYZ​:U​: $x) {
say $x[1] } }; XYZ(3,4,5) # checking
<p6eval> rakudo 57eaaa​: OUTPUT«4␤»
<quietfanatic> er
<pmichaud> I'm not sure it's _correct_; that just appears to be what
Rakudo is doing.
<quietfanatic> r​: class XYZ { method postcircumfix​:<( )>(XYZ​:U​: $x) {
say $x } }; XYZ(3,4,5)
<p6eval> rakudo 57eaaa​: OUTPUT«3 4 5␤»
<quietfanatic> yeah I'm pretty sure that's wrong.
<quietfanatic> where's masakbot?
<sorear> quietfanatic​: 3,4,5 are being wrapped into a capture.
<quietfanatic> Yes, but the signature should unwrap the capture.
<pmichaud> there may be some circularity sawing taking place there...
probably need to check with jnthn++, too.

Meanwhile, later...

<masak> re http://irclog.perlgeek.de/perl6/2012-07-07#i_5793473 -- I
agree with quietfanatic++, and I think sorear++ changed the spec and
fixed Niecza to be more consistent and simpler in this regard. I don't
believe there are circularity issues.
<masak> if jnthn concurs (or doesn't fly into a tantrum about having
to change this bit), I'll submit a rakudobug.
<jnthn> It used to be spec'd that way.
<jnthn> I agreed it could change already.
<jnthn> Rakudo didn't get updated yet.
<jnthn> It was mostly SMOP that wanted it to be the other way, fwiw.
<masak> yes, I remember that bit of input coming from pmurias++ and ruoso++
* masak submits rakudobug
<jnthn> That particular circularity saw doesn't apply to anything
6model-y. 6model doesn't care for captures in any sense, and the
invocation protocol is specified as VM specific.
<jnthn> Rakudo's postcircumfix​:<( )> isn't the invocation protocol in general.
<jnthn> SMOP tried to make it that way, which was why it wanted said
circularity saw, iirc.
<jnthn> .oO( Can I just fix this, or do I have to think about
deprecation policy... :-) )
<masak> the invocation protocol is VM specific, but I do hope the
expected parameter list for postcircumfix​:<( )> isn't.
<jnthn> masak​: That was kinda my point. What postcircumfix​:<( )> does
isn't anything to do with the VM's view.
<masak> ok ok good.
<masak> that's probably wise.

@p6rt
Copy link
Author

p6rt commented Nov 21, 2012

From @grondilu

class Foo {
  has $.str;
  method postcircumfix​:<( )>($i, $k) { $.str.substr​: $i, $k }
}
my Foo $x .= new​: :str("hello");
say $x(2, 1)

rakudo bf472b​: OUTPUT«Not enough positional parameters passed; got 2 but expected 3␤ in method
  postcircumfix​:<( )> at /tmp/AbMJCtzaIi​:1␤ in at src/gen/BOOTSTRAP.pm​:852␤ in any at
  src/gen/BOOTSTRAP.pm​:836␤ in block
  at /tmp/AbMJCtzaIi​:1␤␤»
..niecza v22-36-g19fa03a​: OUTPUT«l␤»

@p6rt
Copy link
Author

p6rt commented Feb 15, 2015

From @Mouq

I merged #​112642 ("postcircumfix​:<( )> refuses to deliver empty capture") and #​115850 ("postcircumfix​:<( )> method fails to accept several arguments") into #​114026 ("postcircumfix​:<( )> invocations get a Capture object, should just get the signature in Rakudo") because all of these tickets were reporting unexpected behavior where postcircumfix​:<( )> was being called with capture of the arguments it was being given, rather than calling it like a normal signature. In other words, they were all reporting the same bug.

This was fixed by hoelzro++ in Rakudo commit​:

commit d5c67dc3289df41dc4ba1a51221911f16b9aa5fb
Author​: Rob Hoelz <rob@​hoelz.ro>
Date​: Tue Jan 27 19​:37​:08 2015 -0600

  Don't pass capture to invoke/postcircumfix​:<( )> when performing Type(...)

  If a user wants to override the behavior of Type(...), they have to know
  that the invoke/postcircumfix​:<( )> method takes a single argument that
  is a Capture, rather than the actual values provided. This is an
  implementation detail, not in the spec, and unintuitive.

Marking as open and testneeded.

@p6rt
Copy link
Author

p6rt commented Feb 15, 2015

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

@p6rt
Copy link
Author

p6rt commented Sep 24, 2015

From @skids

Tests added in S13-overloading/typecasting-long.t

However there is a subcase still behaving magically, and two tests were fudged for it​:

$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​:) { 42 } }; XYX().perl.say;'
XYX(Any)
$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​: $x) { 42 } }; XYX().perl.say;'
XYX(Any)
$ # But the dotted for does behave correctly, and so do :D invocants.
$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​: $x) { 42 } }; XYX.().perl.say;'
Too few positionals passed; expected 2 arguments but got 1
  in method postcircumfix​:<( )> at -e​:1
  in block <unit> at -e​:1
$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​: $x) { 42 } }; XYX.new()().perl.say;'
Too few positionals passed; expected 2 arguments but got 1
  in method postcircumfix​:<( )> at -e​:1
  in block <unit> at -e​:1

@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

From @jnthn

On Wed Sep 23 17​:14​:20 2015, bri@​abrij.org wrote​:

Tests added in S13-overloading/typecasting-long.t

However there is a subcase still behaving magically, and two tests
were fudged for it​:

$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​:) { 42 } };
XYX().perl.say;'
XYX(Any)
$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​: $x) { 42 }
}; XYX().perl.say;'
XYX(Any)
$ # But the dotted for does behave correctly, and so do :D invocants.
$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​: $x) { 42 }
}; XYX.().perl.say;'
Too few positionals passed; expected 2 arguments but got 1
in method postcircumfix​:<( )> at -e​:1
in block <unit> at -e​:1
$ perl6 -e 'class XYX { method postcircumfix​:<( )>(XYX​:U​: $x) { 42 }
}; XYX.new()().perl.say;'
Too few positionals passed; expected 2 arguments but got 1
in method postcircumfix​:<( )> at -e​:1
in block <unit> at -e​:1

The form TypeName(TypeName) is (syntactically) a coercion type literal. And SomeType() is also a coercion type literal, and short for SomeType(Any). This is a parse-time distinction. The . is needed to force it to be a call. So, the behavior seen here is correct.

I've updated the tests in S13-overloading/typecasting-long.t to reflect this.

/jnthn

@p6rt p6rt closed this as completed Nov 12, 2015
@p6rt
Copy link
Author

p6rt commented Nov 12, 2015

@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
Projects
None yet
Development

No branches or pull requests

1 participant