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

Top level local variable is not file scope with mruby command #4931

Closed
shuujii opened this issue Jan 17, 2020 · 1 comment
Closed

Top level local variable is not file scope with mruby command #4931

shuujii opened this issue Jan 17, 2020 · 1 comment

Comments

@shuujii
Copy link
Contributor

shuujii commented Jan 17, 2020

Is the following behavior intentional?

Files

# a.rb
a = 1
# b.rb
p a

mruby

$ bin/mruby -r ./a.rb b.rb
1

Ruby

$ ruby -r ./a.rb b.rb
Traceback (most recent call last):
b.rb:1:in `<main>': undefined local variable or method `a' for main:Object (NameError)
dearblue added a commit to dearblue/mruby that referenced this issue Jan 19, 2020
dearblue added a commit to dearblue/mruby that referenced this issue Jan 19, 2020
Ref mruby#4931

With this change, the `_` variable is defined after the `-r` switch.
@dearblue
Copy link
Contributor

I tried to fix it as #4933, but @shuujii pointed out a new problem.
#4933 (comment)

Based on that, I discovered and commented on a problem that occurred in mruby binary and will leave it here too.
#4933 (comment)
#4933 (comment)

# c.rb
a, b, c = 1, 2, 3
A = -> { b = -2; [a, b, c] }
# d.rb
a, b = 5, 6
p A.call
p a, b
% bin/mrbc c.rb
% bin/mrbc d.rb
% bin/mruby -b -r c.rb d.rb
[5, -2, main]
5
-2

This result can also be confirmed at https://travis-ci.com/dearblue/mruby/jobs/281490648#L1473.

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

2 participants