Skip Menu |
Report information
Id: 127117
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cpan [at] zoffix.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [LTA ERROR] methods declared outside of class {...}
Download (untitled) / with headers
text/plain 1.1k
If you have a file that declares class Foo { ... } and then you define a method OUTSIDE of those curlies and then proceed to call it from another method declared inside of those curclies, you receive a confusing message that talks about attribute access and no hints that you're calling a method that's outside the class's definition. Attached is a sample class that can be called with `perl6 -I. -MFoo -e 'Foo.new.bar'` to reproduce the error. Which on my machine looks like this: zoffix@ZofMain:/tmp/tmp.DPywLvk6la$ cat > Foo.pm6 class Foo { has @!bars = <foo bar ber mer>; method bar { self.mers; } } method mers { say @!bars; } zoffix@ZofMain:/tmp/tmp.DPywLvk6la$ perl6 -I. -MFoo -e 'Foo.new.bar' ===SORRY!=== Error while compiling /tmp/tmp.DPywLvk6la/Foo.pm6 Cannot understand @!bars in this context at /tmp/tmp.DPywLvk6la/Foo.pm6:7 ------> say @!bars⏏; ===SORRY!=== Error while compiling /tmp/tmp.DPywLvk6la/Foo.pm6 Cannot understand @!bars in this context at /tmp/tmp.DPywLvk6la/Foo.pm6:7 ------> say @!bars⏏; zoffix@ZofMain:/tmp/tmp.DPywLvk6la$ perl6 -v This is Rakudo version 2015.12-64-g6612747 built on MoarVM version 2015.12 implementing Perl 6.c. zoffix@ZofMain:/tmp/tmp.DPywLvk6la$
Subject: Foo.pm6
Download Foo.pm6
application/octet-stream 112b

Message body not shown because it is not plain text.

Download (untitled) / with headers
text/plain 478b
Well, declaring methods outside of class scopes is a feature: Show quoted text
> perl6 -e 'class Foo { has $.foo; }; my $bar = my method bar() { say "bar $.foo"; }; Foo.^add_method("bar", $bar); Foo.new(:foo<foo>).bar;'
bar foo Of course, as the method is outside the class scope, it cannot access private attributes. Do you have a suggestion on how we could detect this situation and what the error message should look like?
Download (untitled) / with headers
text/plain 259b
Show quoted text
> Well, declaring methods outside of class scopes is a feature:
Didn't realize it was a feature. My only suggestion would be to change "in this context" to "methods declared outside of class declaration" (or something like that). Not sure how doable that is.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org