[ruby-core:113829] [Ruby master Bug#19721] IO#timeout= can be called without required argument

Issue #19721 has been reported by andrykonchin (Andrew Konchin). ---------------------------------------- Bug #19721: IO#timeout= can be called without required argument https://bugs.ruby-lang.org/issues/19721 * Author: andrykonchin (Andrew Konchin) * Status: Open * Priority: Normal * ruby -v: 3.2.1 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ```ruby f = File.open("a.txt", "w") f.timeout=() # => nil ``` `IO#timeout=` requires an argument (or it's supposed to require it) but if it's called as a method it seems the check is skipped and missing argument is treated as `nil` value. If it's called with `#send` - then argument presence is checked: ```ruby f.send :"timeout=" # ...:in `timeout=': wrong number of arguments (given 0, expected 1) (ArgumentError) ``` -- https://bugs.ruby-lang.org/

Issue #19721 has been updated by ufuk (Ufuk Kayserilioglu). I believe the syntax `f.timeout=()` is _not_ calling the `timeout=` method with no parameters, but instead it is assigning `()` to `f.timeout` attribute. Since `()` in Ruby evaluates to `nil`, since it is an empty subexpression, in essence, that line should be equivalent to `f.timeout = nil`. That's why you get the `nil` value. You can check that this expression gets turned into an assigment by looking at the AST generated from `f.timeout=()` on https://ruby-syntax-tree.github.io/: ``` program (statements ((assign (field (vcall (ident "f")) (period ".") (ident "timeout")) (paren (statements ((void_stmt)))) )) ) ) ``` ---------------------------------------- Bug #19721: IO#timeout= can be called without required argument https://bugs.ruby-lang.org/issues/19721#change-103476 * Author: andrykonchin (Andrew Konchin) * Status: Open * Priority: Normal * ruby -v: 3.2.1 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ```ruby f = File.open("a.txt", "w") f.timeout=() # => nil ``` `IO#timeout=` requires an argument (or it's supposed to require it) but if it's called as a method it seems the check is skipped and missing argument is treated as `nil` value. If it's called with `#send` - then argument presence is checked: ```ruby f.send :"timeout=" # ...:in `timeout=': wrong number of arguments (given 0, expected 1) (ArgumentError) ``` -- https://bugs.ruby-lang.org/

Issue #19721 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Open to Rejected All assignment methods called via `recv.method = ` are called with one argument. `()` is translated to `nil` by the compiler, because it is an expression that is evaluated to `nil`: ```ruby eval('()') # => nil ``` ---------------------------------------- Bug #19721: IO#timeout= can be called without required argument https://bugs.ruby-lang.org/issues/19721#change-103477 * Author: andrykonchin (Andrew Konchin) * Status: Rejected * Priority: Normal * ruby -v: 3.2.1 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ```ruby f = File.open("a.txt", "w") f.timeout=() # => nil ``` `IO#timeout=` requires an argument (or it's supposed to require it) but if it's called as a method it seems the check is skipped and missing argument is treated as `nil` value. If it's called with `#send` - then argument presence is checked: ```ruby f.send :"timeout=" # ...:in `timeout=': wrong number of arguments (given 0, expected 1) (ArgumentError) ``` -- https://bugs.ruby-lang.org/

Issue #19721 has been updated by andrykonchin (Andrew Konchin). Ah, I see. Thank you. ---------------------------------------- Bug #19721: IO#timeout= can be called without required argument https://bugs.ruby-lang.org/issues/19721#change-103480 * Author: andrykonchin (Andrew Konchin) * Status: Rejected * Priority: Normal * ruby -v: 3.2.1 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ```ruby f = File.open("a.txt", "w") f.timeout=() # => nil ``` `IO#timeout=` requires an argument (or it's supposed to require it) but if it's called as a method it seems the check is skipped and missing argument is treated as `nil` value. If it's called with `#send` - then argument presence is checked: ```ruby f.send :"timeout=" # ...:in `timeout=': wrong number of arguments (given 0, expected 1) (ArgumentError) ``` -- https://bugs.ruby-lang.org/
participants (3)
-
andrykonchin (Andrew Konchin)
-
jeremyevans0 (Jeremy Evans)
-
ufuk (Ufuk Kayserilioglu)