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

Signature specifiers on Callables do not consider multi candidates #2045

Closed
zoffixznet opened this issue Jul 10, 2018 · 1 comment
Closed
Labels
consensus needed Needs a well-versed decision with justification, possibly from a core developer

Comments

@zoffixznet
Copy link
Contributor

zoffixznet commented Jul 10, 2018

What's the purpose of specifying something like &foo:($ --> Int) as a parameter in signatures? My understanding is so that I can specify that I only take a particular kind of routines, this way if I write &foo:($ --> Int), I know I can invoke the routine given to me as an argument with a single argument and use the result as an Int.

However, such purpose is currently not served completely. If you pass a multi routine as a Callable, even if there is a candidate that matches the specified signature, the constraint still fails:

Zoffix | m: multi foo ($) {}; multi foo () {}; -> &:() { }( &foo )
camelia | rakudo-moar  08a54212e: OUTPUT: «Constraint type check failed in binding to  parameter '<anon>'; 
expected anonymous constraint to be met but  got Sub (proto sub foo (;; Mu ...)␤ in block <unit> at <tmp>  line 1␤␤»
@zoffixznet zoffixznet added the consensus needed Needs a well-versed decision with justification, possibly from a core developer label Jul 10, 2018
@zoffixznet
Copy link
Contributor Author

zoffixznet commented Jul 10, 2018

Oh, nm, I just realized why it's not implemented this way:

m: multi foo (Int) { "fail" }; multi foo ($ --> Int) {}; multi foo () {}; -> &bar:($ --> Int) { say "{bar 42} is an Int?" }( &foo )

Above, the multi would get accepted because there is a matched sig, but there also exists an unmatched candidate and THAT candidate would actually get called inside my block, and give me a Str instead of an Int I was expecting, making the constraint pointless.

And if one does want to accept a multi with any matching candidate, a simple where .candidates».signature.any ~~ :(&bar:($ --> Int)) would do the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus needed Needs a well-versed decision with justification, possibly from a core developer
Projects
None yet
Development

No branches or pull requests

1 participant