From 9625a9a7d11a1591ee68fa6d8103a4f51355b6fd Mon Sep 17 00:00:00 2001 From: Wayward Heart <91356680+WaywardHeart@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:10:19 -0500 Subject: [PATCH 1/2] Fix hacky superclassing The previous fix didn't do quite enough --- vm_insnhelper.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 7f4b07d418..7e984430eb 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -4483,10 +4483,11 @@ vm_check_if_class(ID id, rb_num_t flags, VALUE super, VALUE klass) // edited for mkxp-z // makes some hackier forms of subclassing possible again - if (0) { //tmp != super) { - rb_raise(rb_eTypeError, - "superclass mismatch for class %"PRIsVALUE"", - rb_id2str(id)); + if (tmp != super) { + return klass == 1 ? -1 : 1; + //rb_raise(rb_eTypeError, + // "superclass mismatch for class %"PRIsVALUE"", + // rb_id2str(id)); } else { return klass; @@ -4566,11 +4567,18 @@ vm_define_class(ID id, rb_num_t flags, VALUE cbase, VALUE super) /* find klass */ rb_autoload_load(cbase, id); if ((klass = vm_const_get_under(id, flags, cbase)) != 0) { - if (!vm_check_if_class(id, flags, super, klass)) + // edited for mkxp-z + // makes some hackier forms of subclassing possible again + VALUE ret = vm_check_if_class(id, flags, super, klass); + if (!ret) { unmatched_redefinition("class", cbase, id, klass); + } else if (ret != klass) { + goto override_class; + } return klass; } else { +override_class: return vm_declare_class(id, flags, cbase, super); } } From dc5f88d9d50905da5e739344e3e63cca8b54bc2f Mon Sep 17 00:00:00 2001 From: Wayward Heart <91356680+WaywardHeart@users.noreply.github.com> Date: Tue, 2 Apr 2024 20:27:05 -0500 Subject: [PATCH 2/2] Don't error on else without rescue --- parse.y | 3 ++- spec/ruby/language/rescue_spec.rb | 2 ++ test/ruby/test_parse.rb | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/parse.y b/parse.y index e3e680414a..10f7249a9e 100644 --- a/parse.y +++ b/parse.y @@ -1403,7 +1403,8 @@ begin_block : '{' top_compstmt '}' bodystmt : compstmt opt_rescue - k_else {if (!$2) {yyerror1(&@3, "else without rescue is useless");}} + // k_else {if (!$2) {yyerror1(&@3, "else without rescue is useless");}} + k_else {if (!$2) {rb_warn0("else without rescue is useless");}} compstmt opt_ensure { diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb index 4d164b38c6..91d481e08d 100644 --- a/spec/ruby/language/rescue_spec.rb +++ b/spec/ruby/language/rescue_spec.rb @@ -238,6 +238,7 @@ class ArbitraryException < StandardError ScratchPad.recorded.should == [:one, :else_ran, :ensure_ran, :outside_begin] end +if false it "raises SyntaxError when else is used without rescue and ensure" do -> { eval <<-ruby @@ -249,6 +250,7 @@ class ArbitraryException < StandardError ruby }.should raise_error(SyntaxError, /else without rescue is useless/) end +end it "will not execute an else block if an exception was raised" do result = begin diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index d697a29c1c..2bf2ad4cc7 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -16,6 +16,7 @@ def test_error_line assert_syntax_error('------,,', /\n\z/, 'Message to pipe should end with a newline') end +if false def test_else_without_rescue assert_syntax_error(<<-END, %r":#{__LINE__+2}: else without rescue"o, [__FILE__, __LINE__+1]) begin @@ -24,6 +25,7 @@ def test_else_without_rescue end END end +end def test_alias_backref assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't make alias/) do