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

No such global error when trying to write a closure #8

Open
martin-t opened this issue Apr 20, 2021 · 1 comment
Open

No such global error when trying to write a closure #8

martin-t opened this issue Apr 20, 2021 · 1 comment
Assignees
Labels
wontfix This will not be worked on

Comments

@martin-t
Copy link

Code:

function f() -> begin
    let local = 123;
    let o = object begin
        function m() -> local;
    end;
    o.m();
end;

f();

Error:

thread 'main' panicked at 'Interpreter error: Error evaluating get global #3:

Caused by:
    No such global `local`.', src/main.rs:141:14

I guess FML doesn't support closures but it should probably error when compiling, not interpreting.

@kondziu
Copy link
Owner

kondziu commented Feb 18, 2022

I have a practical argument against doing it. Let's start with the fact that this is correct:

function f() -> begin
    let local = 123;
    let o = object begin
        function m() -> local;
    end;
    o.m();
end;

let local = 5;

f();

I order to detect that there is a global used in m that is declared later on, there would have to be a whole separate compiler pass to detect this. It's probably not worth the effort.

@kondziu kondziu self-assigned this Feb 18, 2022
@kondziu kondziu added the wontfix This will not be worked on label Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants