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

Error: Signature-less Methods #4985

Open
p6rt opened this issue Jan 3, 2016 · 3 comments
Open

Error: Signature-less Methods #4985

p6rt opened this issue Jan 3, 2016 · 3 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Jan 3, 2016

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

Searchable as RT127137$

@p6rt
Copy link
Author

p6rt commented Jan 3, 2016

From @zoffixznet

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␤»

@p6rt
Copy link
Author

p6rt commented Jan 3, 2016

From @lizmat

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-archive.perl.org/perl6/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.

<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

@p6rt
Copy link
Author

p6rt commented Jan 3, 2016

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

@p6rt p6rt added the LTA Less Than Awesome; typically an error message that could be better label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

1 participant