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

begin/ensure variable scope incorrect? #78

Open
Maccool opened this issue Jan 8, 2020 · 0 comments
Open

begin/ensure variable scope incorrect? #78

Maccool opened this issue Jan 8, 2020 · 0 comments

Comments

@Maccool
Copy link

Maccool commented Jan 8, 2020

if I execute the following code with mruby:

strX = 'some no foo'
begin
	y='start'
	puts y
	foo
rescue => excp
	strX = 'some foo error'
ensure
	puts strX
	puts 'end'
end
return

I get the output:

start
some foo error
end

Without the error line ( comment out 'foo') it's:
start
some no foo
end

In mod_mruby the scope of a variable is not carried into the ensure:

strX = 'some no foo'
begin
	y='start'
	Apache.echo y
	foo
rescue => excp
	strX = 'some foo error'
ensure
	Apache.echo strX
	Apache.echo 'end'
end
return

Output from this is:

start

end

The variable seen by the ensure is set to nil (tested by getting an error if you attempt " strX += 'more text' " or some other manipulation of the nil value string). This could be intentional, but I wanted to be sure that this was working as designed or a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant