Skip to content

Commit

Permalink
Merge pull request #4982 from vrurg/fix-nominalizable-coercion-regres…
Browse files Browse the repository at this point in the history
…sion

Fix a regression where coercing into a role didn't work
  • Loading branch information
vrurg committed Jul 13, 2022
2 parents e7acf49 + 0e09a28 commit 7e300e6
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/vm/moar/dispatchers.nqp
Expand Up @@ -3695,15 +3695,15 @@ nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-isinvokable', -> $cap
elsif nqp::defined(
$method := nqp::tryfindmethod(
nqp::what($value),
nqp::how($nominal_target).name($nominal_target)))
nqp::how_nd($nominal_target).name($nominal_target)))
&& method-cando($method, $value)
{
# There is .TargetType method on the value, use it
$coercer := $coerce-by-type-method;
}
elsif nqp::defined($method := nqp::tryfindmethod(
(nqp::how($nominal_target).archetypes.composable
?? ($nominal_target := nqp::how($nominal_target).pun($nominal_target))
(nqp::how_nd($nominal_target).archetypes.composable
?? ($nominal_target := nqp::how_nd($nominal_target).pun($nominal_target))
!! $nominal_target),
'COERCE'))
&& method-cando($method, $nominal_target, $value)
Expand Down Expand Up @@ -3738,7 +3738,7 @@ nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-isinvokable', -> $cap
$coercer := $coerce-runtime;
}

nqp::list($coercer, $method)
nqp::list($coercer, $method, $nominal_target)
}

nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-coercion', -> $capture {
Expand Down Expand Up @@ -3817,8 +3817,7 @@ nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-isinvokable', -> $cap
my @cdesc := select-coercer($coercion, $value);
my $coercer := @cdesc[0]; # Code object to do the coercion
my $method := @cdesc[1];
my $use-runtime := @cdesc[2];
my $nominal_target := $coercionHOW.nominal_target($coercion);
my $nominal_target := @cdesc[2];

if nqp::isconcrete($coercer) {
# We found an acceptable coercer, use it
Expand Down Expand Up @@ -3886,29 +3885,33 @@ nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-isinvokable', -> $cap
!! return_error($ret, $type)
}

my $check_type_typeobj_coerce := -> $ret, $type, $coercion, $coercer, $method {
# For @cdesc values see select-coercer sub
my $check_type_typeobj_coerce := -> $ret, $type, $coercion, @cdesc {
!nqp::isconcrete($ret) && nqp::istype($ret, $type)
?? $coercer(
$coercion, $ret, $method,
nqp::how($coercion).nominal_target($coercion),
?? @cdesc[0]( # coercer code
$coercion, $ret,
@cdesc[1], # coercing method
@cdesc[2], # nominal target
nqp::how($coercion).target_type($coercion))
!! return_error($ret, $type)
}

my $check_type_concrete_coerce := -> $ret, $type, $coercion, $coercer, $method {
my $check_type_concrete_coerce := -> $ret, $type, $coercion, @cdesc {
nqp::isconcrete($ret) && nqp::istype($ret, $type)
?? $coercer(
$coercion, $ret, $method,
nqp::how($coercion).nominal_target($coercion),
?? @cdesc[0](
$coercion, $ret,
@cdesc[1],
@cdesc[2],
nqp::how($coercion).target_type($coercion))
!! return_error($ret, $type)
}

my $check_type_coerce := -> $ret, $type, $coercion, $coercer, $method {
my $check_type_coerce := -> $ret, $type, $coercion, @cdesc {
nqp::istype($ret, $type)
?? $coercer(
$coercion, $ret, $method,
nqp::how($coercion).nominal_target($coercion),
?? @cdesc[0](
$coercion, $ret,
@cdesc[1],
@cdesc[2],
nqp::how($coercion).target_type($coercion))
!! return_error($ret, $type)
}
Expand Down Expand Up @@ -4039,11 +4042,9 @@ nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-isinvokable', -> $cap
my $checker-capture :=
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj', $capture,
2, $coercion-type),
3, @cdesc[0]), # coercer code
4, @cdesc[1]), # coercion method object
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj', $capture,
2, $coercion-type),
3, @cdesc), # coercer code
0, $checker);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant', $checker-capture);
}
Expand Down

0 comments on commit 7e300e6

Please sign in to comment.