Project

General

Profile

Bug #14061

Top-level return does not execute ensure if the file is loaded pr required

Added by Eregon (Benoit Daloze) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-10-26 trunk 60450) [x86_64-linux]
[ruby-core:83589]

Description

While writing specs for top-level return in https://github.com/ruby/spec/pull/530,
we found an inconsistent behavior:

puts "before begin"
begin
  return
ensure
  puts "within ensure"
end
puts "after begin"
$ ruby test.rb
before begin
within ensure

$ ruby -r./test.rb -e0
before begin

$ ruby -e 'load "test.rb"'
before begin

This is inconsistent, I believe ensure should be executed in both cases.
The semantics of top-level return are like raising an exception implicitly caught by load/require and the top-level exception handler, except for this case.


Related issues

Related to Ruby trunk - Bug #13844: Toplevel returns should fire ensuresClosedActions

Associated revisions

Revision 84d93141
Added by nobu (Nobuyoshi Nakada) over 1 year ago

compile.c: ensure after return in library toplevel

  • compile.c (compile_return): execute ensure clause after toplevel return even in library toplevel other than the main script. [ruby-core:83589] [Bug #14061]

test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60590
Added by nobu (Nobuyoshi Nakada) over 1 year ago

compile.c: ensure after return in library toplevel

  • compile.c (compile_return): execute ensure clause after toplevel return even in library toplevel other than the main script. [ruby-core:83589] [Bug #14061]

test

Revision 60590
Added by nobu (Nobuyoshi Nakada) over 1 year ago

compile.c: ensure after return in library toplevel

  • compile.c (compile_return): execute ensure clause after toplevel return even in library toplevel other than the main script. [ruby-core:83589] [Bug #14061]

test

Revision 60590
Added by nobu (Nobuyoshi Nakada) over 1 year ago

compile.c: ensure after return in library toplevel

  • compile.c (compile_return): execute ensure clause after toplevel return even in library toplevel other than the main script. [ruby-core:83589] [Bug #14061]

test

History

#1

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Related to Bug #13844: Toplevel returns should fire ensures added
#2

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r60590.


compile.c: ensure after return in library toplevel

  • compile.c (compile_return): execute ensure clause after toplevel return even in library toplevel other than the main script. [ruby-core:83589] [Bug #14061]

test

Also available in: Atom PDF