Skip Menu |
Report information
Id: 127137
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] Signature-less Methods
The error is made when the programmer assumes method declarations without a signature mean any arguments are valid and not a (). This would be common with Perl 5 programmers, I can imagine. Moreover, whe error that is shown when a call to such a method is made says it received 1 more argument than what the user provided, and it's not obvious that the one extra is the invocant. In constrast, doing the same thing with plain subroutines shows a much clearer and more informative error message. <Zoffix> m: class Foo { method bar {say "uhum"} }; Foo.new.bar: 42; <camelia> rakudo-moar 4bb47d: OUTPUT«Too many positionals passed; expected 1 argument but got 2␤ in method bar at /tmp/fub1N6RN3q line 1␤ in block <unit> at /tmp/fub1N6RN3q line 1␤␤» <Zoffix> m: sub bar { say "uhum" }; bar 42 <camelia> rakudo-moar 4bb47d: OUTPUT«===SORRY!=== Error while compiling /tmp/V0xL_4prhM␤Calling bar(Int) will never work with declared signature ()␤at /tmp/V0xL_4prhM:1␤------> sub bar { say "uhum" }; ⏏bar 42␤»
To: "Zoffix Znet (via RT)" <perl6-bugs-followup [...] perl.org>
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Subject: Re: [perl #127137] [LTA ERROR] Signature-less Methods
Date: Sun, 3 Jan 2016 23:00:01 +0100
Download (untitled) / with headers
text/plain 1.9k
Show quoted text
> On 03 Jan 2016, at 20:59, Zoffix Znet (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Zoffix Znet > # Please include the string: [perl #127137] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=127137 > > > > The error is made when the programmer assumes method declarations without a signature mean any arguments are valid and not a (). This would be common with Perl 5 programmers, I can imagine. > > Moreover, whe error that is shown when a call to such a method is made says it received 1 more argument than what the user provided, and it's not obvious that the one extra is the invocant. > > In constrast, doing the same thing with plain subroutines shows a much clearer and more informative error message. > > > <Zoffix> m: class Foo { method bar {say "uhum"} }; Foo.new.bar: 42; > <camelia> rakudo-moar 4bb47d: OUTPUT«Too many positionals passed; expected 1 argument but got 2␤ in method bar at /tmp/fub1N6RN3q line 1␤ in block <unit> at /tmp/fub1N6RN3q line 1␤␤»
This *also* applies when there *is* a signature specified. $ 6 'class Foo { method bar() {say "uhum"} }; Foo.new.bar: 42' Too many positionals passed; expected 1 argument but got 2 in method bar at -e line 1 in block <unit> at -e line 1 So, the LTAness of this error message is more generic. I’ll see if I can do something about that. Show quoted text
> <Zoffix> m: sub bar { say "uhum" }; bar 42 > <camelia> rakudo-moar 4bb47d: OUTPUT«===SORRY!=== Error while compiling /tmp/V0xL_4prhM␤Calling bar(Int) will never work with declared signature ()␤at /tmp/V0xL_4prhM:1␤------> sub bar { say "uhum" }; ⏏bar 42␤»
This is possible because the optimizer can figure this out at compile time. It’s not possible (yet, anyway) to do this for methods. It will probably be quite some time before we will see this type of message for method calls :-( Liz


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