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

multi dispatch calls multi with named args even when none are passed and named-arg-less candidate is available #5918

Closed
p6rt opened this issue Dec 27, 2016 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Dec 27, 2016

Migrated from rt.perl.org#130415 (status was 'rejected')

Searchable as RT130415$

@p6rt
Copy link
Author

p6rt commented Dec 27, 2016

From @zoffixznet

In this code, I would've expected the second multi to be used, since I'm not providing
any named args. I'm fuzzy on whether named params affect multi dispatch, but even if they
wouldn't the multi without any named params is later in the source​:

  $ cat test.p6
  multi foo($, :$) { say "there"; }
  multi foo($ ) { say "here"; }
  foo 42;

  $ perl6 test.p6
  there

A bit of a discussion here​: https://irclog.perlgeek.de/perl6/2016-12-27#i_13807727


I also had this to include in the ticket, though I now see it's likely unrelated,
and the throwage happens when the optimizer simply tries to work out which candidate
to call during optimization stage. And the case where throwage is avoided is simply
because the optimizer doesn't go far enough to actually call the multi. Including it anyway...7

If we make the multi that wasn't called above call itself with args matching no candidate​:

  $ cat test.p6
  multi foo($, :$) { say "there"; }
  multi foo($ ) { foo $, $; }
  foo 42;

  $ perl6 test.p6
  ===SORRY!=== Error while compiling test.p6
  Calling foo(Mu, Mu) will never work with any of these multi signatures​:
  ($, $)
  ($)
  at test.p6​:2
  ------> multi foo($ ) { ⏏foo $, $; }

Yet it still works like in the first case, if we turn off the optimizer​:

  $ cat test.p6
  multi foo($, :$) { say "there"; }
  multi foo($x ) { foo $x, $; }
  foo 42;

  $ perl6 test.p6
  there

@p6rt
Copy link
Author

p6rt commented Dec 27, 2016

From @zoffixznet

I messed up the end of the ticket, should read​:

Yet it still works like in the first case, if we turn off the
optimizer​:

  $ perl6 --optimize=off test.p6
  there

Or give a name to the parameter​:

  $ cat test.p6
  multi foo($, :$) { say "there"; }
  multi foo($x ) { foo $x, $; }
  foo 42;

$ perl6 test.p6
there

@p6rt
Copy link
Author

p6rt commented Feb 9, 2017

From @zoffixznet

On Tue, 27 Dec 2016 11​:02​:17 -0800, cpan@​zoffix.com wrote​:

In this code, I would've expected the second multi to be used, since
I'm not providing
any named args. I'm fuzzy on whether named params affect multi
dispatch, but even if they
wouldn't the multi without any named params is later in the source​:

$ cat test.p6
multi foo($, :$) { say "there"; }
multi foo($ ) { say "here"; }
foo 42;

$ perl6 test.p6
there

A bit of a discussion here​: https://irclog.perlgeek.de/perl6/2016-12-
27#i_13807727

-------------------------------------------------------------------------------------
I also had this to include in the ticket, though I now see it's likely
unrelated,
and the throwage happens when the optimizer simply tries to work out
which candidate
to call during optimization stage. And the case where throwage is
avoided is simply
because the optimizer doesn't go far enough to actually call the
multi. Including it anyway...7

If we make the multi that wasn't called above call itself with args
matching no candidate​:

$ cat test.p6
multi foo($, :$) { say "there"; }
multi foo($ ) { foo $, $; }
foo 42;

$ perl6 test.p6
===SORRY!=== Error while compiling test.p6
Calling foo(Mu, Mu) will never work with any of these multi
signatures​:
($, $)
($)
at test.p6​:2
------> multi foo($ ) { ⏏foo $, $; }

Yet it still works like in the first case, if we turn off the
optimizer​:

$ cat test.p6
multi foo($, :$) { say "there"; }
multi foo($x ) { foo $x, $; }
foo 42;

$ perl6 test.p6
there

Not a bug. See explanation by jnthn++​: https://irclog.perlgeek.de/perl6/2017-02-09#i_14074677

@p6rt p6rt closed this as completed Feb 9, 2017
@p6rt
Copy link
Author

p6rt commented Feb 9, 2017

@zoffixznet - Status changed from 'new' to 'rejected'

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