Skip to content

Commit

Permalink
Merge pull request #4110 from usev6/jvm_coercive_optional
Browse files Browse the repository at this point in the history
[JVM] Make optional coercive parameter work again
  • Loading branch information
usev6 committed Dec 13, 2020
2 parents 1c43c46 + 856dfb2 commit 5e791d7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/vm/jvm/runtime/org/raku/rakudo/Binder.java
Expand Up @@ -218,6 +218,8 @@ private static int juncOrFail(ThreadContext tc, RakOps.GlobalExt gcx, SixModelOb
* re-enters the binder. Returns one of the BIND_RESULT_* codes. */
private static final CallSiteDescriptor genIns = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
private static final CallSiteDescriptor targetType = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
private static final CallSiteDescriptor ACCEPTS_o = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ, CallSiteDescriptor.ARG_OBJ }, null);
private static final CallSiteDescriptor ACCEPTS_i = new CallSiteDescriptor(
Expand Down Expand Up @@ -812,7 +814,22 @@ else if ((flags & SIG_ELEM_HASH_SIGIL) != 0) {
case SIG_ELEM_NATIVE_STR_VALUE:
return createBox(tc, gcx, null, CallSiteDescriptor.ARG_STR);
default:
return param.get_attribute_boxed(tc, gcx.Parameter, "$!type", HINT_type);
/* Do a coercion, if one is needed. */
SixModelObject paramType = param.get_attribute_boxed(tc, gcx.Parameter, "$!type", HINT_type);
SixModelObject HOW = paramType.st.HOW;
SixModelObject archetypesMeth = Ops.findmethod(HOW, "archetypes", tc);
Ops.invokeDirect(tc, archetypesMeth, Ops.invocantCallSite, new Object[] { HOW });
SixModelObject Archetypes = Ops.result_o(tc.curFrame);
SixModelObject coerciveMeth = Ops.findmethodNonFatal(Archetypes, "coercive", tc);
if (coerciveMeth != null) {
Ops.invokeDirect(tc, coerciveMeth, Ops.invocantCallSite, new Object[] { Archetypes });
if (Ops.istrue(Ops.result_o(tc.curFrame), tc) == 1) {
SixModelObject targetTypeMeth = Ops.findmethod(HOW, "target_type", tc);
Ops.invokeDirect(tc, targetTypeMeth, targetType, new Object[] { HOW, paramType });
return Ops.result_o(tc.curFrame);
}
}
return paramType;
}
}
}
Expand Down

0 comments on commit 5e791d7

Please sign in to comment.