Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions spec/ruby/language/rescue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 13 additions & 5 deletions vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down