From bc50f2a3f1d166be3899f32b81bb78f666000592 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 26 May 2024 20:14:18 +0900 Subject: [PATCH] Debug unexpectedly changed path --- error.c | 6 ++++-- test/ruby/test_literal.rb | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/error.c b/error.c index 5f8111df57..4398019b40 100644 --- a/error.c +++ b/error.c @@ -2719,8 +2719,10 @@ syntax_error_with_path(VALUE exc, VALUE path, VALUE *mesg, rb_encoding *enc) rb_ivar_set(exc, id_i_path, path); } else { - if (rb_attr_get(exc, id_i_path) != path) { - rb_raise(rb_eArgError, "SyntaxError#path changed"); + VALUE old_path = rb_attr_get(exc, id_i_path); + if (old_path != path) { + rb_raise(rb_eArgError, "SyntaxError#path changed: %+"PRIsVALUE"->%+"PRIsVALUE, + old_path, path); } VALUE s = *mesg = rb_attr_get(exc, idMesg); if (RSTRING_LEN(s) > 0 && *(RSTRING_END(s)-1) != '\n') diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index c6154af1f6..b0fd4680b3 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -640,11 +640,16 @@ class TestRubyLiteral < Test::Unit::TestCase end begin r2 = eval(s) - rescue NameError, SyntaxError + rescue SyntaxError => e + r2 = :err + rescue NameError r2 = :err end r2 = :err if Range === r2 - assert_equal(r1, r2, "Float(#{s.inspect}) != eval(#{s.inspect})") + s = s.inspect + mesg = "Float(#{s}) != eval(#{s})" + mesg << ":" << e.message if e + assert_equal(r1, r2, mesg) } } }