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

Something quite scary happens when the wrong number of positional parameters is sent to a method or sub with a hash param in Rakudo #1452

Closed
p6rt opened this issue Dec 20, 2009 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 20, 2009

Migrated from rt.perl.org#71478 (status was 'resolved')

Searchable as RT71478$

@p6rt
Copy link
Author

p6rt commented Dec 20, 2009

From @masak

<masak> rakudo​: class A { method foo($_​: $b) {} }; A.new.foo(1, 2)
<p6eval> rakudo 8dc189​: ( no output )
<masak> locally, "Too many positional parameters passed; got 3 but expected 2"
<masak> (which is fine, but now...)
<masak> rakudo​: class A { method foo($_​: %b) {} }; A.new.foo(1, 2)
<p6eval> rakudo 8dc189​: ( no output )
<masak> locally, "Nominal type check failed for parameter
'11111111111000000000100000101100'; expected Associative but got Int
instead"
<masak> (which means that locally, I'm doing this​: o.O)
* masak submits rakudobug
<masak> rakudo​: sub foo(%h) {}; foo(1, 2)
<p6eval> rakudo 8dc189​: ''' is not a valid sprintf format [...]
<masak> something weird is definitely going on here...

@p6rt
Copy link
Author

p6rt commented Apr 19, 2010

From @jnthn

On Sun Dec 20 13​:52​:01 2009, masak wrote​:

<masak> rakudo​: class A { method foo($_​: $b) {} }; A.new.foo(1, 2)
<p6eval> rakudo 8dc189​: ( no output )
<masak> locally, "Too many positional parameters passed; got 3 but
expected 2"
<masak> (which is fine, but now...)
<masak> rakudo​: class A { method foo($_​: %b) {} }; A.new.foo(1, 2)
<p6eval> rakudo 8dc189​: ( no output )
<masak> locally, "Nominal type check failed for parameter
'11111111111000000000100000101100'; expected Associative but got Int
instead"
<masak> (which means that locally, I'm doing this​: o.O)
* masak submits rakudobug

Fixed this one a couple of weeks ago, but failed to find the ticket.
Just ran across it. :-) Now​:

class A { method foo($_​: %b) {} }; A.new.foo(1, 2)
Nominal type check failed for parameter '%b'; expected Associative but
got Int instead

<masak> rakudo​: sub foo(%h) {}; foo(1, 2)
<p6eval> rakudo 8dc189​: ''' is not a valid sprintf format [...]
<masak> something weird is definitely going on here...

And​:

sub foo(%h) {}; foo(1, 2)
Nominal type check failed for parameter '%h'; expected Associative but
got Int instead

Given to moritz++ for a spectest; checking that %h features somewhere in
the error message will probably work nicely.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Apr 19, 2010

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

@p6rt
Copy link
Author

p6rt commented Apr 30, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S06-signature/errors.t

commit eb0fb473ff6dfd31d3a250ee6878793de81360c4
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Fri Apr 30 15​:46​:40 2010 +0000

  [t/spec] test for RT #​71478, sensible error message for passing two arguments to one hash parameter
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;30518 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S06-signature/errors.t b/t/spec/S06-signature/errors.t
index 1ee9f31..439be84 100644
--- a/t/spec/S06-signature/errors.t
+++ b/t/spec/S06-signature/errors.t
@@ -1,8 +1,8 @@
-use v6;
+    use v6;
 
 use Test;
 
-plan 5;
+    plan 9;
 
 =begin pod
 
@@ -15,7 +15,7 @@ sub foo (*$x) { 1 }
 dies_ok  { foo(reverse(1,2)) }, 'slurpy args are now bounded (1)';
 
 sub bar (*@x) { 1 }
-lives_ok { bar(reverse(1,2)) }, 'slurpy args are now bounded (2)';  
+lives_ok { bar(reverse(1,2)) }, 'slurpy args are not bounded (2)';  
 
 eval_dies_ok 'sub quuux ($?VERSION) { ... }',
              'parser rejects magicals as args (1)';
@@ -30,4 +30,15 @@ eval_dies_ok('sub quuuux ($!) { ... }',
             'argument passed to sub with empty signature';
 }
 
+# RT #71478
+{
+    my $success = eval 'sub foo(%h) { }; foo(1, 2); 1';
+    my $error   = "$!";
+    nok $success,
+        "Passing two arguments to a function expecting one hash is an error";
+    ok $error ~~ / '%h' /,   '... error message mentions parameter';
+    ok $error ~~ /:i 'type' /, '... error message mentions "type"';
+    ok $error ~~ / Associative /, '... error message mentions "Associative"';
+}
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Apr 30, 2010

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Apr 30, 2010
@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
Labels
Projects
None yet
Development

No branches or pull requests

1 participant