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

Compiler allows use of outer scoped runtime variables from an fn defined inside it #876

Closed
tgschultz opened this Issue Mar 31, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@tgschultz
Contributor

tgschultz commented Mar 31, 2018

fn outer(y: u32) fn(u32) u32 {
    const st = struct {
        fn get(z: u32) u32 {
            return z + y;
        }
    };
    return st.get;
}

test "reference runtime variable in outer function scope" {
    var func = outer(10);
    var x = func(3);
}

Oddly the test fails in this instance, usually I just get segfaults.
This is actually useful behavior for comptime vars and constants as it can be used to create a sort of comptime closure.

@tgschultz tgschultz changed the title from Compiler allows use of runtime variables from an fn defined inside it to Compiler allows use of outer scoped runtime variables from an fn defined inside it Mar 31, 2018

@andrewrk andrewrk added the bug label Mar 31, 2018

@andrewrk andrewrk added this to the 0.3.0 milestone Mar 31, 2018

@andrewrk andrewrk closed this in 1d8b8ad Sep 6, 2018

@andrewrk

This comment has been minimized.

Member

andrewrk commented Sep 6, 2018

screenshot_2018-09-05_20-37-39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment