On Wed May 05 00:22:54 2010, jimmy wrote:
> JimmyZ>  rakudo: my class bar { method Str() { '11'; }; };  multi sub
> foo(bar $x as Int is copy) { say ++$x }; augment class bar { method
> Int() { '10' }};    foo(bar.new());
> 
>  p6eval>   rakudo 1eef08: OUTPUT«Can't augment class bar without 'use
> MONKEY_TYPING'␤current instr.: 'perl6;Perl6;Grammar;add_name' pc 42888
> (src/gen/perl6-grammar.pir:353)␤»
> 
> JimmyZ>  rakudo: my class bar { method Str() { '11'; }; };  multi sub
> foo(bar $x as Int is copy) { say ++$x }; my augment class bar { method
> Int() { '10' }};    foo(bar.new());
> p6eval>   rakudo 1eef08: OUTPUT«Malformed my at line 11, near "augment
> cl"␤current instr.: 'perl6;HLL;Grammar;panic' pc 501 (ext/nqp-
> rx/src/stage0/HLL-s0.pir:327)␤»
> 
> JimmyZ>  rakudo: my class bar { method Str() { '11'; }; };  multi sub
> foo(bar $x as Int is copy) { say ++$x }; augment my class bar { method
> Int() { '10' }};    foo(bar.new());
> p6eval>   rakudo 1eef08: OUTPUT«Malformed augment at line 11, near "my
> class b"␤current instr.: 'perl6;HLL;Grammar;panic' pc 501
> (ext/nqp-rx/src/stage0/HLL-s0.pir:327)␤»
> 
> In order to discourage casual misuse of these declarators, they are
> not
> allowed on global classes unless you put a special declaration at the
> top:
>         use MONKEY_TYPING;
> this is from: http://perlcabal.org/syn/S12.html#line_2022
> 
> 在此祝你身体健康,天天快乐
> 卓明亮
> 

This appears to do something closer to the right thing now:

If you remove the "my" from the augment:

19:18 <[Coke]> rakudo: use MONKEY_TYPING;my class bar { method Str() { '11'; };
               }; multi sub foo(bar $x as Int  is copy) { say ++$x }; augment
               class bar { method Int() { '10' }}; foo(bar.new());
19:18 <p6eval> rakudo ebd4d8: OUTPUT«Type check failed in assignment to '$x';
               expected 'bar' but got 'Str'␤  in sub prefix:<++> at
               src/gen/CORE.setting:1050␤  in sub foo at /tmp/xUD1IINzZM:1␤  in
               block <anon> at /tmp/xUD1IINzZM:1␤  in <anon> at
               /tmp/xUD1IINzZM:1␤␤»

It allows the augment and then complains about the '10' you passed to ++

This matches with a straight sub that does the same thing:

19:21 <[Coke]> rakudo: sub foo (Int $x as Str) { say $x.WHAT}; foo(3)
19:21 <p6eval> rakudo ebd4d8: OUTPUT«Str()␤»
19:23 <[Coke]> rakudo: sub foo (Int $x as Str) { say $x.WHAT}; foo('3')
19:23 <p6eval> rakudo ebd4d8: OUTPUT«Nominal type check failed for parameter
               '$x'; expected Int but got Str instead␤  in sub foo at
               /tmp/9Ad8a8pUd8:1␤  in block <anon> at /tmp/9Ad8a8pUd8:1␤  in
               <anon> at /tmp/9Ad8a8pUd8:1␤␤»


So I think this is closable modulo tests.


-- 
Will "Coke" Coleda

Reply via email to