From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 5125617D3872 for ; Thu, 3 Oct 2013 15:54:23 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 805B8B5D860 for ; Thu, 3 Oct 2013 15:23:15 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 627B697A826 for ; Thu, 3 Oct 2013 15:23:17 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D-NMddLsDwq4 for ; Thu, 3 Oct 2013 15:23:17 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 27EF097A820 for ; Thu, 3 Oct 2013 15:23:17 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 9C18A952439 for ; Thu, 3 Oct 2013 15:23:14 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 10BDD120489; Thu, 3 Oct 2013 15:23:05 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from fluorine.ruby-lang.org (fluorine.ruby-lang.org [210.251.121.216]) by neon.ruby-lang.org (Postfix) with ESMTP id F2033120457 for ; Thu, 3 Oct 2013 15:23:01 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by fluorine.ruby-lang.org (Postfix) with ESMTP id AB8933FEC1 for ; Thu, 3 Oct 2013 15:23:01 +0900 (JST) Date: Thu, 3 Oct 2013 15:23:01 +0900 From: "myronmarston (Myron Marston)" To: ruby-core@ruby-lang.org Message-Id: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Redmine-Issue-Author: myronmarston X-Auto-Response-Suppress: OOF X-Redmine-Issue-Id: 8982 X-Redmine-Mailinglistintegration-Message-Ids: 31293 X-Mailer: Redmine X-Redmine-Project: ruby-trunk Auto-Submitted: auto-generated X-Redmine-Site: Ruby Issue Tracking System X-Redmine-Host: bugs.ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 57629 Subject: [ruby-core:57629] [ruby-trunk - Bug #8982][Open] NoMethodError#message produces surprising output when #inspect is defined on an anonymous class X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #8982 has been reported by myronmarston (Myron Marston). ---------------------------------------- Bug #8982: NoMethodError#message produces surprising output when #inspect is defined on an anonymous class https://bugs.ruby-lang.org/issues/8982 Author: myronmarston (Myron Marston) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN Given the following script: ``` def raise_no_method_error_for_anonymous_class_with_inspect(&block) klass = Class.new do define_method(:inspect, &block) end begin instance = klass.new puts "#inspect output: #{instance.inspect} (#{instance.inspect.length} chars)" instance.undefined_method rescue NoMethodError => e puts e.message end puts end raise_no_method_error_for_anonymous_class_with_inspect do "#" end raise_no_method_error_for_anonymous_class_with_inspect do "" end raise_no_method_error_for_anonymous_class_with_inspect do "#" end raise_no_method_error_for_anonymous_class_with_inspect do "#" end ``` It produces the following output: ``` #inspect output: # (19 chars) undefined method `undefined_method' for # #inspect output: (18 chars) undefined method `undefined_method' for :# #inspect output: # (65 chars) undefined method `undefined_method' for # #inspect output: # (66 chars) undefined method `undefined_method' for #<#:0x101726698> ``` There are two surprising things here: * It matters whether or not the first character in my `inspect` is a `#`. If it's not, ruby appends the class's `#inspect` output to it. * It matters how long my `inspect` string is. If it's less than 66 characters, it's used; if it's more than 65, it's discarded, and the default anonymous `#inspect` is used instead. Both of these things are extremely surprising and seem very arbitrary and inconsistent. I brought this up on ruby parley and @charliesome was kind enough to point me to the code that's the source of this issue: https://github.com/ruby/ruby/blob/870dc20922d1ab0b628d24e64e971e8eb77ecd61/error.c#L1091-1104 So it looks intentional, but I think this is a bug. -- http://bugs.ruby-lang.org/