Playing around I found that the following change made your examples work as expected:
diff --git a/src/Perl6/Optimizer.nqp b/src/Perl6/Optimizer.nqp index 12398ba..9102b7f 100644 --- a/src/Perl6/Optimizer.nqp +++ b/src/Perl6/Optimizer.nqp @@ -1082,7 +1082,8 @@ class Perl6::Optimizer { || nqp::istype($op[0][0], QAST::Stmts) && nqp::istype(($c1 := $op[0][0][0]), QAST::Op) && nqp::existskey(%range_bounds, $c1.name)) && - $!symbols.is_from_core($c1.name) { + $!symbols.is_from_core($c1.name) && + nqp::defined($op[0][1].ann('code_object')) { self.optimize_for_range($op, $op[0][1], $c1); self.visit_op_children($op); return $op; $ ./perl6 -e '^4 .map: {};' Cannot map a Range to a Hash. Did you mean to add a stub ({...}) or did you mean to .classify? in block <unit> at -e line 1 $ ./perl6 -e '^4 .map: 42;' Cannot resolve caller map(Range: Int); none of these signatures match: ($: Hash \h, *%_) (\SELF: █; :$label, :$item, *%_) (HyperIterable:D $: █; :$label, *%_) in block <unit> at -e line 1 $ ./perl6 -e 'sub foo ($) {say "meow"}; ^4 .map: &foo;' meow meow meow meow The original error came from the first two lines in 'method optimize_for_ranges' in src/Perl6/Optimizer.nqp. For some reason $callee.ann('code_object') did not return a code object as expected. method optimize_for_range($op, $callee, $c2) { my $code := $callee.ann('code_object'); my $count := $code.count; Now, I have no idea whether my change from above makes sense or whether the annotation for 'code_object' was wrong in the first place.