While testing some of the OO code examples and having some PHASERS(specifically a CONTROL PHASER) installed I ran across a MoarVM Panic.  The code is from the 'Object orientation' page - https://docs.perl6.org/language/objects. A syntax error on my part in calling the constructor with a CONTROL PHASER installed causes it.

use v6;

CONTROL { say 'PHASER: CONTROL' } #  catch control exceptions, before LEAVE

{
    say '--- ', $?LINE;
    my $ⲧ = " " xx 4;
    class Journey {
        has $.origin;
        has $.destination;
        has @.travelers;
        has Str $.notes is rw;

        multi method notes() { "$!notes\n" };
        multi method notes( Str $note ) { $!notes ~= "$note\n$ⲧ" };

        method Str { "⤷ $!origin\n$ⲧ" ~ self.notes() ~ "$!destination ⤶\n" };
    }

    #my $trip = Journey.new( :origin<Here>, :destination<There>, travelers => <þor Freya> );  # from doc - works     #my $trip = Journey.new( origin => "Here", destination => "There", travelers => ["þor", "Freya"] );  # same - works

    my $trip = Journey.new( :origin{"Here"}, :destination<There>, travelers => <þor Freya> );  # change of < > to {" "} - only for %hash - fails with MoarVM panic

    $trip.travelers[0].say;
    $trip.travelers[1].say;
    $trip.travelers.say;
    $trip.notes("First steps");
    notes $trip: "Almost there";
    print $trip;

    # OUTPUT:
    #⤷ Here
    #       First steps
    #       Almost there
    #
    #There ⤶
}

=begin pod
# output if CONTROL {} phaser commented out
--- 8
þor
Freya
[þor Freya]
Block object coerced to string (please use .gist or .perl to do that)
  in method Str at ./MoarVMPanic.p6 line 19
⤷
       First steps
         First steps
       Almost there

There ⤶
=end pod

=begin pod
# output if CONTROL {} phaser commented in
--- 8
þor
Freya
[þor Freya]
PHASER: CONTROL
Block object coerced to string (please use .gist or .perl to do that)
  in method Str at ./MoarVMPanic.p6 line 19
MoarVM panic: Trying to unwind over wrong handler
=end pod

rahogaboom

Reply via email to