[ruby-core:60667] [Backport200 - Backport #9248] Struct methods, segmentation fault

From: eregontp@...
Date: 2014-02-12 14:48:52 UTC
List: ruby-core #60667
Issue #9248 has been updated by Benoit Daloze.


This still seems problematic:

    c = Struct.new(:a?)
    
    o = c.new(42)
    
    o.send("a?=", 3) rescue p $! # => #<NoMethodError: undefined method `a?=' for #<struct :a?=42>>
    p o.a?
    
    p o.methods # removing the "p" here would produce a NoMethodError below, somehow this "fixes" everything
    
    o.send("a?=", 3)
    p o.a?

IMHO, adding methods not callable by default because they do not respect the symbol syntax is bad. I would much prefer just to forbid attributes with a final question mark in Struct (or make them behave as the attribute without the "?" and just an extra "#{attr}?" predicate). 

----------------------------------------
Backport #9248: Struct methods, segmentation fault
https://bugs.ruby-lang.org/issues/9248#change-45096

* Author: H H
* Status: Closed
* Priority: Normal
* Assignee: Tomoyuki Chikanaga
* Category: 
* Target version: 
* ruby -v: 2.0.0p353
----------------------------------------
=begin
The following snippet causes segmentation fault:

(({p Struct.new(:method_with_questionmark?).new.methods}))

This happens when accessor method name contains question mark.
=end




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

In This Thread