Skip to content

Instantly share code, notes, and snippets.

@usev6
Last active July 15, 2016 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usev6/aac530b87dd24c0261e257b75c7ceaf5 to your computer and use it in GitHub Desktop.
Save usev6/aac530b87dd24c0261e257b75c7ceaf5 to your computer and use it in GitHub Desktop.
Avoid tpye check error 'expected Positional but got Seq' on rakudo-j
$ ./perl6-j -e 'sub foo (@a) { say @a.perl }; my $foo = gather { take 2; take 4 }; foo($foo)'
Type check failed in binding @a; expected Positional but got Seq ((2, 4).Seq)
in sub foo at -e line 1
in block <unit> at -e line 1
$ vim src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
$ git diff
diff --git a/src/vm/jvm/runtime/org/perl6/rakudo/Binder.java b/src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
index d46ede9..c574c52 100644
--- a/src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
+++ b/src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
@@ -356,11 +356,18 @@ public final class Binder {
/* If the expected type is Positional, see if we need to do the
* positional bind failover. */
- if (nomType == gcx.Positional && Ops.istype_nodecont(arg_o, gcx.PositionalBindFailover, tc) != 0) {
- SixModelObject ig = Ops.findmethod(tc, arg_o, "cache");
- Ops.invokeDirect(tc, ig, Ops.invocantCallSite, new Object[] { arg_o });
- arg_o = Ops.result_o(tc.curFrame);
- decontValue = Ops.decont(arg_o, tc);
+ if (nomType == gcx.Positional) {
+ if (Ops.istype_nodecont(arg_o, gcx.PositionalBindFailover, tc) != 0) {
+ SixModelObject ig = Ops.findmethod(tc, arg_o, "cache");
+ Ops.invokeDirect(tc, ig, Ops.invocantCallSite, new Object[] { arg_o });
+ arg_o = Ops.result_o(tc.curFrame);
+ decontValue = Ops.decont(arg_o, tc);
+ }
+ else if (Ops.istype_nodecont(decontValue, gcx.PositionalBindFailover, tc) != 0) {
+ SixModelObject ig = Ops.findmethod(tc, decontValue, "cache");
+ Ops.invokeDirect(tc, ig, Ops.invocantCallSite, new Object[] { decontValue });
+ decontValue = Ops.result_o(tc.curFrame);
+ }
}
/* If not, do the check. If the wanted nominal type is Mu, then
$ ./perl6-j -e 'sub foo (@a) { say @a.perl }; my $foo = gather { take 2; take 4 }; foo($foo)'
(2, 4)
@usev6
Copy link
Author

usev6 commented Jul 15, 2016

For some reasons the error goes away if we work with 'decontValue' and not 'arg_o'.

In other cases like my $a = Bag.new("a", "b", "b"); say $a.roll(2) 'arg_o' seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment