Skip to content

Commit

Permalink
Fix for JVM backend
Browse files Browse the repository at this point in the history
Wrong argument was passed into `CoercionHOW::coerce`.

- Added `COERCE` candidate to Str to handle native strings
- Fixed a `nqp::die` in `CoercionHOW::coerce`
  • Loading branch information
vrurg committed Nov 15, 2020
1 parent 9f62532 commit 34bc0b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/Perl6/Metamodel/CoercionHOW.nqp
Expand Up @@ -202,11 +202,13 @@ class Perl6::Metamodel::CoercionHOW
~ (nqp::defined($coerced_decont) ?? "an instance of" !! "a type object")
~ " " ~ $coerced_name;
}
if %ex {
unless nqp::isnull(%ex) {
%ex<X::Coerce::Impossible>($target_type_name, $value_type_name, $hint)
}
nqp::die("Impossible coercion from " ~ $value_type.HOW.name($value_type_name)
~ " into " ~ $target_type_name ~ ": " ~ $hint);
nqp::die("Impossible coercion from "
~ $value_type_name
~ " into " ~ $target_type_name
~ ": " ~ $hint);
}

$coerced_value
Expand Down
5 changes: 5 additions & 0 deletions src/core.c/Str.pm6
Expand Up @@ -62,6 +62,11 @@ my class Str does Stringy { # declared in BOOTSTRAP
multi method Stringy(Str:D:) { self }
multi method DUMP(Str:D: --> Str:D) { self.raku }

proto method COERCE(|) {*}
multi method COERCE(Mu \s) {
self.new(:value(nqp::p6box_s(s)))
}

method Int(Str:D: --> Int:D) {
nqp::istype((my $n := self.Numeric),Int) || nqp::istype($n,Failure)
?? $n
Expand Down
7 changes: 2 additions & 5 deletions src/vm/jvm/runtime/org/raku/rakudo/Binder.java
Expand Up @@ -379,7 +379,7 @@ else if (desiredNative == 0) {
boolean didHLLTransform = false;
SixModelObject paramType = param.get_attribute_boxed(tc, gcx.Parameter, "$!type", HINT_type);
SixModelObject ContextRef = null;
SixModelObject HOW = null;
SixModelObject HOW = paramType.st.HOW;
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 @@ -390,14 +390,12 @@ else if (desiredNative == 0) {
if (decontValue != beforeHLLize)
didHLLTransform = true;


/* Skip nominal type check if not needed. */
if (!noNomTypeCheck) {
/* Is the nominal type 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.) */
if ((paramFlags & SIG_ELEM_TYPE_GENERIC) != 0) {
HOW = paramType.st.HOW;
SixModelObject ig = Ops.findmethod(HOW,
"instantiate_generic", tc);
ContextRef = tc.gc.ContextRef;
Expand Down Expand Up @@ -514,9 +512,8 @@ else if (Ops.istype_nd(decontValue, gcx.PositionalBindFailover, tc) != 0) {
return BIND_RESULT_FAIL;
}

HOW = paramType.st.HOW;
SixModelObject coerceMeth = Ops.findmethod(HOW, "coerce", tc);
Ops.invokeDirect(tc, coerceMeth, genIns, new Object[] { HOW, paramType, origArg });
Ops.invokeDirect(tc, coerceMeth, genIns, new Object[] { HOW, paramType, arg_o });
arg_o = Ops.result_o(tc.curFrame);
decontValue = Ops.decont(arg_o, tc);
}
Expand Down

0 comments on commit 34bc0b9

Please sign in to comment.