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

self in Class.^add_method is not a Class object #4633

Open
p6rt opened this issue Oct 8, 2015 · 3 comments
Open

self in Class.^add_method is not a Class object #4633

p6rt opened this issue Oct 8, 2015 · 3 comments
Labels
Bug

Comments

@p6rt
Copy link

@p6rt p6rt commented Oct 8, 2015

Migrated from rt.perl.org#126301 (status was 'open')

Searchable as RT126301$

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 8, 2015

From @skaji

(Note that the script is also at
https://gist.github.com/shoichikaji/e0baf95e6f602a443f16 )

Following script exits with error​:

$ cat test.p6
class A {}

class B {
  sub foo(A $a) {}
  A.^add_method('bar', method () {
  foo(self);
  });
}

$ perl6 -v
This is perl6 version 2015.09-289-g6f31121 built on MoarVM version
2015.09-69-g741cb9c

$ perl6 test.p6
===SORRY!=== Error while compiling test.p6
Calling foo(B) will never work with declared signature (A $a)
at test.p6​:6
------> foo(self);

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 20, 2015

From @jonathanstowe

Hi,
I think that is more like a parsing problem, because the "self" in the method in general is clearly the right object​:

class A {}

class B {
  sub foo(A $a) {}
  A.^add_method('bar', method () {
  say self.perl;
  #foo(self);
  });
}

A.new.bar; # > A.new

A possible workaround is​:

class A {}

class B {
  sub foo(A $a) { say $a.perl}
  A.^add_method('bar', method () {
  my $a = self;
  foo($a);
  });
}

A.new.bar # > A.new

Don't know if that helps.

On Thu Oct 08 07​:49​:41 2015, skaji@​outlook.com wrote​:

(Note that the script is also at
https://gist.github.com/shoichikaji/e0baf95e6f602a443f16 )

Following script exits with error​:

$ cat test.p6
class A {}

class B {
sub foo(A $a) {}
A.^add_method('bar', method () {
foo(self);
});
}

$ perl6 -v
This is perl6 version 2015.09-289-g6f31121 built on MoarVM version
2015.09-69-g741cb9c

$ perl6 test.p6
===SORRY!=== Error while compiling test.p6
Calling foo(B) will never work with declared signature (A $a)
at test.p6​:6
------> foo(self);

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 20, 2015

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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.