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

Private methods in classes misparsed as variables? #546

Closed
p6rt opened this issue Dec 27, 2008 · 7 comments
Closed

Private methods in classes misparsed as variables? #546

p6rt opened this issue Dec 27, 2008 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Dec 27, 2008

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

Searchable as RT61774$

@p6rt
Copy link
Author

p6rt commented Dec 27, 2008

From publiustemp-perl6users@yahoo.com

Not even remotely sure how to describe this, but​:

  class Foo {
  has @​something is rw;

  method doit {
  @​something = <1 2 3>;
  say self!something;
  }

  my method something () {
  return "Hello, World!";
  }
  }
  my Foo $foo .= new;
  $foo.doit;

That prints '123'.

Comment out the @​something lines and it prints "Hello, World!" as expected.

$ svn info; uname -a
Path​: .
URL​: https://svn.perl.org/parrot/trunk
Repository Root​: https://svn.perl.org/parrot
Repository UUID​: d31e2699-5ff4-0310-a27c-f18f2fbe73fe
Revision​: 34446
Node Kind​: directory
Schedule​: normal
Last Changed Author​: kjs
Last Changed Rev​: 34446
Last Changed Date​: 2008-12-27 21​:17​:55 +0000 (Sat, 27 Dec 2008)

Darwin curtis-poes-computer-3.local 9.5.1 Darwin Kernel Version 9.5.1​: Fri Sep 19 16​:19​:24 PDT 2008; root​:xnu-1228.8.30~1/RELEASE_I386 i386

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

@p6rt
Copy link
Author

p6rt commented Dec 29, 2008

From @moritz

On Sat Dec 27 14​:05​:50 2008, publiustemp-perl6users@​yahoo.com wrote​:

Not even remotely sure how to describe this, but​:

class Foo \{
    has @&#8203;something is rw;

    method doit \{
        @&#8203;something = \<1 2 3>;
        say self\!something;
    \}

    my method something \(\) \{
        return "Hello, World\!";
    \}

If you have a method with the same name as an attribute, you override
the accessor to that attribute.

Note that
has @​something;
just creates an alias to @​.something, which in turn desugars into the
method call @​( self.something )

\}
my Foo $foo \.= new;
$foo\.doit;

That prints '123'.

Which means that user-defined methods can't override implictly generated
accessors, which is the real bug here.

Thanks for your report,
Moritz

@p6rt
Copy link
Author

p6rt commented Dec 29, 2008

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

@p6rt
Copy link
Author

p6rt commented Jun 2, 2009

From @pmichaud

This now works as of c907d37​:

  $ cat 61774
  class A {
  has @​something is rw;
  method doit {
  @​something = <1 2 3>;
  say self!something;
  }
  my method something {
  "Hello, world";
  }
  }

  my A $a .= new;
  $a.doit;

  $ ./perl6 61774
  Hello, world

Assigning ticket for spectest verification...and then we can close the
ticket. Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Jun 30, 2009

From @jnthn

Assigning to moritz++ for spectests (as if I write tests :-P).

@p6rt
Copy link
Author

p6rt commented Jun 30, 2009

From @moritz

Added as test to the ever-growing spec/S12-methods/instance.t.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jun 30, 2009

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

@p6rt p6rt closed this as completed Jun 30, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant