Skip to content

Commit

Permalink
[JVM] Handle generic types in coercions on params
Browse files Browse the repository at this point in the history
This ports the fix from 6902d51eb7
to the jvm backend (and makes RT #126383 pass).
  • Loading branch information
usev6 committed May 10, 2018
1 parent c66a6f0 commit 7d2940e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
Expand Up @@ -377,6 +377,8 @@ else if (desiredNative == 0) {
SixModelObject decontValue = null;
boolean didHLLTransform = false;
SixModelObject nomType = null;
SixModelObject ContextRef = null;
SixModelObject HOW = null;
if (flag == CallSiteDescriptor.ARG_OBJ && !(is_rw && desiredNative != 0)) {
/* We need to work on the decontainerized value. */
decontValue = Ops.decont(arg_o, tc);
Expand All @@ -395,10 +397,10 @@ else if (desiredNative == 0) {
nomType = param.get_attribute_boxed(tc, gcx.Parameter,
"$!nominal_type", HINT_nominal_type);
if ((paramFlags & SIG_ELEM_NOMINAL_GENERIC) != 0) {
SixModelObject HOW = nomType.st.HOW;
HOW = nomType.st.HOW;
SixModelObject ig = Ops.findmethod(HOW,
"instantiate_generic", tc);
SixModelObject ContextRef = tc.gc.ContextRef;
ContextRef = tc.gc.ContextRef;
SixModelObject cc = ContextRef.st.REPR.allocate(tc, ContextRef.st);
((ContextRefInstance)cc).context = cf;
Ops.invokeDirect(tc, ig, genIns,
Expand Down Expand Up @@ -513,10 +515,29 @@ else if (Ops.istype_nodecont(decontValue, gcx.PositionalBindFailover, tc) != 0)
return BIND_RESULT_FAIL;
}

/* Is the coercion target generic and in need of instantiation?
* (This can happen in (::T, T) where we didn't learn about the
* type until during the signature bind.) */
param.get_attribute_native(tc, gcx.Parameter, "$!coerce_method", HINT_coerce_method);
String methName = tc.native_s;
HOW = coerceType.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 genericMeth = Ops.findmethod(Archetypes, "generic", tc);
Ops.invokeDirect(tc, genericMeth, Ops.invocantCallSite, new Object[] { Archetypes });
if (Ops.istrue(Ops.result_o(tc.curFrame), tc) == 1) {
ContextRef = tc.gc.ContextRef;
SixModelObject ctcc = ContextRef.st.REPR.allocate(tc, ContextRef.st);
((ContextRefInstance)ctcc).context = cf;
SixModelObject ctig = Ops.findmethod(HOW, "instantiate_generic", tc);
Ops.invokeDirect(tc, ctig, genIns, new Object[] { HOW, coerceType, ctcc });
coerceType = Ops.result_o(tc.curFrame);
methName = Ops.typeName(coerceType, tc);
}

/* Only coerce if we don't already have the correct type. */
if (Ops.istype(decontValue, coerceType, tc) == 0) {
param.get_attribute_native(tc, gcx.Parameter, "$!coerce_method", HINT_coerce_method);
String methName = tc.native_s;
SixModelObject coerceMeth = Ops.findmethodNonFatal(decontValue, methName, tc);
if (coerceMeth != null) {
Ops.invokeDirect(tc, coerceMeth,
Expand Down

0 comments on commit 7d2940e

Please sign in to comment.