Project

General

Profile

Bug #17727

Updated by colintherobot (Colin Hart) about 4 years ago

Given a method that takes a kwarg and **arg 

 ``` ruby 
 def foo(a:, **b) 
    [a,b] 
 end  
 ``` 

 If you call this method without deconstructing the hash passed to the second argument first it throws an error that that I thought was maybe just an unhandled case. I would Would expect a message indicating you need to deconstruct the hash first.  

 Instead it throws a syntax error: 
 ``` ruby 
 foo(a: '1', {b: 2}) 
 SyntaxError: unexpected ')', expecting => 
 foo(a: '1', {b: 2}) 
                   ^ 
 ``` 

 
 Passing case when you deconstruct the hash first: first 
 ``` ruby 
 foo(a: '1', **{b: 2}) 
 => ["1", {:b=>2}] 
 ``` 

 But wondering if there's something else going on because cause you get a different error when defining this case on multiple lines. If In fact, if you're trying to run this in a the repl environment it won't even let you complete the method call. 

  

 from repl: repl 
 ``` ruby 
 foo( 
   a: '1', 
   {b: 2} 
 SyntaxError: unexpected '\n', expecting => 
 ``` 

 
 passing case: case 
 ``` ruby 
 foo( 
   a: '1',   
   **{b:1} 
 )   
 => ["1", {:b=>1}] 
 ``` 


 Attached is a ruby script to reproduce the above cases. 

Back