Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

augment(or supersede, NYI) doesn't work on non-global classes #1746

Closed
p6rt opened this issue May 5, 2010 · 5 comments
Closed

augment(or supersede, NYI) doesn't work on non-global classes #1746

p6rt opened this issue May 5, 2010 · 5 comments

Comments

@p6rt
Copy link

p6rt commented May 5, 2010

Migrated from rt.perl.org#74910 (status was 'resolved')

Searchable as RT74910$

@p6rt
Copy link
Author

p6rt commented May 5, 2010

From @zhuomingliang

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

�此�你身��康�天天快�
��亮

 

@p6rt
Copy link
Author

p6rt commented Sep 30, 2011

From @coke

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

@p6rt
Copy link
Author

p6rt commented Sep 30, 2011

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 27, 2011

From @moritz

Now tested in S12-class/augment-supersede.t.

@p6rt
Copy link
Author

p6rt commented Nov 27, 2011

@moritz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant