Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong execution order of END block and at_exit callback #2818

Closed
andrykonchin opened this issue Jan 4, 2023 · 2 comments
Closed

Wrong execution order of END block and at_exit callback #2818

andrykonchin opened this issue Jan 4, 2023 · 2 comments

Comments

@andrykonchin
Copy link
Member

END block should be called before at_exit callback

Example:

at_exit { puts "at_exit callback" }

END {
  puts "END code"
}

TruffleRuby:

at_exit callback
END code

Ruby 3.1.3:

END code
at_exit callback

Extracted from a discussion here #2800 (comment)

@andrykonchin andrykonchin changed the title Wrong order of END and at_exit callback Wrong execution order of END and at_exit callback Jan 5, 2023
@andrykonchin andrykonchin changed the title Wrong execution order of END and at_exit callback Wrong execution order of END block and at_exit callback Jan 5, 2023
@andrykonchin
Copy link
Member Author

Example of mixed END blocks and at_exit callbacks (it works on CRuby 2.7-3.2):

    it "runs them all in LIFO order" do
      ruby_exe(<<~RUBY).should == "at_exit#2\nEND#2\nat_exit#1\nEND#1\n"
        END { puts 'END#1' }
        at_exit { puts 'at_exit#1' }
        END { puts 'END#2' }
        at_exit { puts 'at_exit#2' }
      RUBY
    end

@andrykonchin andrykonchin self-assigned this Jan 12, 2023
@andrykonchin
Copy link
Member Author

Fixed in cfc35bb

@andrykonchin andrykonchin added this to the 23.0.0 Release milestone Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant