From 358840fa7d510010ef1f775be567ba2268119e17 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 17 Nov 2014 18:23:09 +0000 Subject: [PATCH] object.c: fix error message * object.c (check_setter_id): show the original argument instead of nil on TypeError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ object.c | 4 ++-- test/ruby/test_module.rb | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d77ccc206..7574523a47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Nov 18 03:23:06 2014 Nobuyoshi Nakada + + * object.c (check_setter_id): show the original argument instead + of nil on TypeError. + Tue Nov 18 03:20:19 2014 Nobuyoshi Nakada * symbol.h (is_{local,global,instance,attrset,const,class,junk}_sym): diff --git a/object.c b/object.c index 372254e8e9..74521f8444 100644 --- a/object.c +++ b/object.c @@ -1930,8 +1930,8 @@ check_setter_id(VALUE name, int (*valid_id_p)(ID), int (*valid_name_p)(VALUE), else { VALUE str = rb_check_string_type(name); if (NIL_P(str)) { - rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol or string", - str); + rb_raise(rb_eTypeError, "% "PRIsVALUE" is not a symbol or string", + name); } if (!valid_name_p(str)) { rb_name_error_str(str, message, QUOTE(str)); diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 5b1f787be0..1696775f50 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -677,14 +677,16 @@ class TestModule < Test::Unit::TestCase def test_const_set_invalid_name c1 = Class.new - assert_raise(NameError) { c1.const_set(:foo, :foo) } - assert_raise(NameError) { c1.const_set("bar", :foo) } - assert_raise(TypeError) { c1.const_set(1, :foo) } + assert_raise_with_message(NameError, /foo/) { c1.const_set(:foo, :foo) } + assert_raise_with_message(NameError, /bar/) { c1.const_set("bar", :foo) } + assert_raise_with_message(TypeError, /1/) { c1.const_set(1, :foo) } assert_nothing_raised(NameError) { c1.const_set("X\u{3042}", :foo) } assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-16be"), :foo) } assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-16le"), :foo) } assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32be"), :foo) } assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32le"), :foo) } + cx = EnvUtil.labeled_class("X\u{3042}") + assert_raise_with_message(TypeError, /X\u{3042}/) { c1.const_set(cx, :foo) } end def test_const_get_invalid_name