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

Parameter '' requires an instance, LTA error #3187

Open
p6rt opened this issue Jul 11, 2013 · 6 comments
Open

Parameter '' requires an instance, LTA error #3187

p6rt opened this issue Jul 11, 2013 · 6 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Jul 11, 2013

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

Searchable as RT118865$

@p6rt
Copy link
Author

p6rt commented Jul 11, 2013

From @zhuomingliang

JimmyZ> r​: sub f(Int $x where $x > 0) { say "yup" }; my Int $a; f($a);
Camellia> rakudo b19f72​: OUTPUT«Parameter '' requires an instance, but a type object was passed␤ in method Bridge at src/gen/CORE.setting​:3562␤ in sub infix​:<>> at src/gen/CORE.setting​:3490␤ in sub infix​:<>> at src/gen/CORE.setting​:3340␤ in sub f at /tmp/RSujJD9_FI​:1␤ in block at /tmp/RSujJ…

The above is missing '$x'.

Timotimo> r​: sub f(Int​:D $x) { say "yup" }; my Int $a; f($a);
camellia> rakudo b19f72​: OUTPUT«Parameter '$x' requires an instance, but a type object was passed␤ in sub f at /tmp/9PHIMfVEzS​:1␤ in block at /tmp/9PHIMfVEzS​:1␤␤»


Jimmy Zhuo

@p6rt
Copy link
Author

p6rt commented Mar 11, 2015

From @usev6

The error message has changed slightly and now states that "Invocant requires an instance".

$ perl6 -e 'sub f(Int $x where $x > 0) { say "yup" }; my Int $a; f($a);'
Invocant requires an instance, but a type object was passed
  in method Bridge at src/gen/m-CORE.setting​:5578
  in sub infix​:<>> at src/gen/m-CORE.setting​:5505
  in method ACCEPTS at src/gen/m-CORE.setting​:3844
  in sub f at -e​:1
  in block <unit> at -e​:1

Formerly the message said "Parameter '' requires an instance" (and the whole bug report is about the missing parameter name $x within this message).

IMHO the current error message is good -- even without speaking about $x.

So, is this closeable?

1 similar comment
@p6rt
Copy link
Author

p6rt commented Mar 11, 2015

From @usev6

The error message has changed slightly and now states that "Invocant requires an instance".

$ perl6 -e 'sub f(Int $x where $x > 0) { say "yup" }; my Int $a; f($a);'
Invocant requires an instance, but a type object was passed
  in method Bridge at src/gen/m-CORE.setting​:5578
  in sub infix​:<>> at src/gen/m-CORE.setting​:5505
  in method ACCEPTS at src/gen/m-CORE.setting​:3844
  in sub f at -e​:1
  in block <unit> at -e​:1

Formerly the message said "Parameter '' requires an instance" (and the whole bug report is about the missing parameter name $x within this message).

IMHO the current error message is good -- even without speaking about $x.

So, is this closeable?

@p6rt
Copy link
Author

p6rt commented Mar 11, 2015

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 12, 2015

From @perlpilot

IMHO, the message is actually slightly worse. Now it's talking about an
invocant when there are no classes or methods involved!

-Scott

On Wed, Mar 11, 2015 at 1​:26 PM, Christian Bartolomaeus via RT <
bugs-comment@​bugs6.perl.org> wrote​:

The error message has changed slightly and now states that "Invocant
requires an instance".

$ perl6 -e 'sub f(Int $x where $x > 0) { say "yup" }; my Int $a; f($a);'
Invocant requires an instance, but a type object was passed
in method Bridge at src/gen/m-CORE.setting​:5578
in sub infix​:<>> at src/gen/m-CORE.setting​:5505
in method ACCEPTS at src/gen/m-CORE.setting​:3844
in sub f at -e​:1
in block <unit> at -e​:1

Formerly the message said "Parameter '' requires an instance" (and the
whole bug report is about the missing parameter name $x within this
message).

IMHO the current error message is good -- even without speaking about $x.

So, is this closeable?

@p6rt
Copy link
Author

p6rt commented Aug 9, 2015

From @skids

FWIW there are two layers to this ticket​: failure on operators, and
faiures within where clauses.

The error is due to a failure during evaluation the where clause
and does not say '$x' for the same reason this does not​:

$ perl6 -e 'my Int $x; my $f = $x > 0;'
Invocant requires an instance of type Int, but a type object was passed. Did you forget a .new?

... The "invocant" is because the '>' operator is finding its candidate
through class methods. That cannot be improved at the runtime bind
site as variable names have been optimized away. Rejecting :Us earlier
in the bridgework might allow the error to occur earlier where more
information is still available, and that would give an eject marker
at the right character in the code​:

$ perl6 -e 'sub b (Str $a) { }; sub f(Int $x where { b(3) } ) { say "yup" }; my Int $a; f($a);'
===SORRY!=== Error while compiling -e
Calling b(int) will never work with declared signature (Str $a)
at -e​:1
------> ub b (Str $a) { }; sub f(Int $x where { ⏏b(3) } ) { say "yup" }; my Int $a; f($a)

...but it has to be done with care for optimizability and could be messy
what with all the multi candidates involved.

As a sidenote, it is not very idiomatic to repeat the parameter name in the
parameter's own where clause, and it would normally be written​:

sub f(Int $x where * > 0)

...and FWIW using Int​:D would yield​:

$ perl6 -e 'sub f(Int​:D $x where * > 0) { say "yup" }; my Int $a; f($a);'
Parameter '$x' requires an instance of type Int, but a type object was passed. Did you forget a .new?

But whether failures that occur during a runtime constraint check should
emit a worry to identify the offending where clause is a good question.
Perhaps where clauses could have an extra implicit CATCH... worry... rethrow,
since they tend to be called so close to the binder.

@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