[#65451] [ruby-trunk - Feature #10333] [PATCH 3/1] optimize: "yoda literal" == string — ko1@...

Issue #10333 has been updated by Koichi Sasada.

9 messages 2014/10/07

[ruby-core:66008] [ruby-trunk - Bug #10456] kwargs and block without comma should probably be a syntax error

From: jacknagel@...
Date: 2014-10-29 23:01:57 UTC
List: ruby-core #66008
Issue #10456 has been updated by Jack Nagel.


```ruby
def wat(something: nil &block)
end
```

 `nil &block` is a legal expression (calling the `&` method on `nil` with `block` as the argument).

The expression is evaluated at method call time, not method definition time, so that's where the (correct) error shows up.

----------------------------------------
Bug #10456: kwargs and block without comma should probably be a syntax error
https://bugs.ruby-lang.org/issues/10456#change-49733

* Author: Robert Ross
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* ruby -v: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
<pre>ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]</pre>

I experienced something very weird, when you define a method like this:

<pre>
def wat(something: nil &block)
end
</pre>

It actually doesn't come back as a syntax error

<pre>
Roberts-MacBook-Pro-2:~ robert$ cat test.rb; echo
def wat(name: "" &block)
end
Roberts-MacBook-Pro-2:~ robert$ ruby -c test.rb
Syntax OK
</pre>

Within the method, the block is never assigned either actually on method call:

<pre>
irb(main):007:0> def wat(something: nil &block)
irb(main):008:1> puts "Block: #{block}"
irb(main):009:1> end
=> :wat
irb(main):010:0> wat(something: 'hello') { "My block here" }
NameError: undefined local variable or method `block' for main:Object
  from (irb):8:in `wat'
  from (irb):10
  from /Users/robert/.rbenv/versions/2.1.1/bin/irb:11:in `<main>'
</pre>

This behavior seems unlikely, it caught me off guard for sure.



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next