Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created Jan 7, 2018
Embed
What would you like to do?
diff --git a/src/Perl6/Actions.nqp b/src/Perl6/Actions.nqp
index 6fe3df9ec..1bd07805a 100644
--- a/src/Perl6/Actions.nqp
+++ b/src/Perl6/Actions.nqp
@@ -8653,24 +8653,30 @@ class Perl6::Actions is HLL::Actions does STDActions {
# Handle coercion.
my $coerce_to := nqp::getattr($param_obj, $Param, '$!coerce_type');
unless nqp::isnull($coerce_to) {
- if $coerce_to.HOW.archetypes.generic {
- return 0;
- }
- $var.push(QAST::Op.new(
- :op('unless'),
- QAST::Op.new(
- :op('istype'),
- QAST::Var.new( :name($name), :scope('local') ),
- QAST::WVal.new( :value($coerce_to) )
- ),
- QAST::Op.new(
- :op('bind'),
- QAST::Var.new( :name($name), :scope('local') ),
- QAST::Op.new(
- :op('callmethod'),
- :name(nqp::getattr_s($param_obj, $Param, '$!coerce_method')),
- QAST::Var.new( :name($name), :scope('local') )
- ))));
+ return 0 if $coerce_to.HOW.archetypes.generic;
+
+ # QAST:
+ # nqp::unless(
+ # nqp::istype($var, $to),
+ # nqp::unless(
+ # nqp::istype(($var := $var."$to"()), $to),
+ # die "Coercion failed"));
+ $var.push:
+ QAST::Op.new: :op<unless>,
+ QAST::Op.new(:op<istype>,
+ QAST::Var.new(:$name, :scope<local>),
+ QAST::WVal.new: :value($coerce_to)),
+ QAST::Op.new: :op<unless>,
+ QAST::Op.new(:op<istype>,
+ QAST::Op.new(:op<bind>,
+ QAST::Var.new(:$name, :scope<local>),
+ QAST::Op.new: :op<callmethod>,
+ :name(nqp::getattr_s($param_obj, $Param,
+ '$!coerce_method')),
+ QAST::Var.new: :$name, :scope<local>),
+ QAST::WVal.new: :value($coerce_to)),
+ QAST::Op.new: :op<call>, :name<&die>,
+ QAST::SVal.new: :value('Coercion failed')
}
# If it's optional, do any default handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment