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

Cannot apply trait 'is cached' on multi candidate #3540

Closed
p6rt opened this issue Oct 4, 2014 · 4 comments
Closed

Cannot apply trait 'is cached' on multi candidate #3540

p6rt opened this issue Oct 4, 2014 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Oct 4, 2014

Migrated from rt.perl.org#122899 (status was 'new')

Searchable as RT122899$

@p6rt
Copy link
Author

p6rt commented Oct 4, 2014

From @FROGGS

FROGGS m​: multi foo(Int) is cached { say 'Int' }; multi foo(Str) { say 'Str' }; foo 1; foo 1; foo 'a'; foo 'a'
camelia rakudo-moar b3331e​: OUTPUT«Cannot invoke object with invocation handler in this context␤ in sub foo at /tmp/zWM01_TzeB​:1␤ in block <unit> at /tmp/zWM01_TzeB​:1␤␤»
FROGGS :/
FROGGS I feared that
lizmat that's odd, the wrap should only be applied to the first
FROGGS m​: multi foo(Int) is cached { say 'Int' }; foo 1; foo 1;
camelia rakudo-moar b3331e​: OUTPUT«Cannot invoke object with invocation handler in this context␤ in sub foo at /tmp/EpBFnacF6n​:1␤ in block <unit> at /tmp/EpBFnacF6n​:1␤␤»
lizmat that's worthy of a rakudobug
FROGGS m​: sub foo(Int) is cached { say 'Int' }; foo 1; foo 1;
camelia rakudo-moar b3331e​: OUTPUT«Int␤»
FROGGS yeah

@p6rt
Copy link
Author

p6rt commented May 29, 2015

From @hoelzro

The attached file contains the following code​:

multi fib(0) { 0 }
multi fib(1) { 1 }
multi fib(Int $n where * >= 0 ) is cached { fib($n - 2) + fib($n - 1) }

say fib(18);

...which, when run, results in the following error message​:

Cannot invoke object with invocation handler in this context
in block <unit> at test.p6​:5

The proper way to fix this code is declare proto fib(Int $) is cached { * }, but that's not obvious from the error message. I'm not sure if this happens with other Routine traits, but I wouldn't be surprised.

@p6rt
Copy link
Author

p6rt commented May 29, 2015

From @hoelzro

test.p6

@lizmat
Copy link
Contributor

lizmat commented Dec 15, 2021

use experimental :cached;
multi fib(0) { 0 }
multi fib(1) { 1 }
multi fib(Int $n where * >= 0 ) is cached { dd; fib($n - 2) + fib($n - 1) }

say fib(18);
say fib(18);

results in:

sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
sub fib(Int $n where { ... })
2584
2584

So the second time we do say fib(18), it does not actually call the candidate.

Closing now.

@lizmat lizmat closed this as completed Dec 15, 2021
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

2 participants