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

error when use << #5921

Open
fab1an2 opened this issue Feb 1, 2023 · 6 comments
Open

error when use << #5921

fab1an2 opened this issue Feb 1, 2023 · 6 comments

Comments

@fab1an2
Copy link

fab1an2 commented Feb 1, 2023

My script working but when i add
długi_napis = <<-KONIEC
bardzo
długi napis
i co?
KONIEC

w = długi_napis
i ger error. I no need use it. Only string put to any variable.
When I declare long string is ok but if I use it is trouble

trace (most recent call last):
[1] prog.rb:19
prog.rb:14:in funkcja: undefined method 'długi_napis' (NoMethodError)

@matz
Copy link
Member

matz commented Feb 2, 2023

I cannot reproduce the error. The code snippet works without any error. Could you show us the full script, please?

@fab1an2
Copy link
Author

fab1an2 commented Feb 2, 2023

wynik = mrb_funcall(mrb, mrb_top_self(mrb), "fun", 0 );
if (mrb->exc) { mrb_print_error(mrb); }
printf("fun() == %s\n", RSTRING_PTR(wynik) );

mrb_close(mrb);

@matz
Copy link
Member

matz commented Feb 2, 2023

Ah, if I understand correctly, you initialized the variable długi_napis at the top-level of the program, and tried to access it from inside the method fun, which has different scope. You cannot access the top-level local variable from methods. It's a standard Ruby behavior.

@fab1an2
Copy link
Author

fab1an2 commented Feb 2, 2023

ok

BTW, can You improve my error functions? It not working in this example, not show error

@matz
Copy link
Member

matz commented Feb 2, 2023

Can you be more concrete? What did you get, and what do you expect for the error?

@dearblue
Copy link
Contributor

dearblue commented Feb 3, 2023

@fab1an2,
It was fixed in #5858 and should be included in the next mruby 3.2.

🐈‍⬛ Also, can you please stop editing comments like #5921 (comment) that have different content?
When I read the whole sequence from the beginning I will not be able to understand the situation.

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

3 participants