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

Weird escape analysis #322

Open
vtereshkov opened this issue Nov 12, 2023 · 2 comments
Open

Weird escape analysis #322

vtereshkov opened this issue Nov 12, 2023 · 2 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@vtereshkov
Copy link
Owner

vtereshkov commented Nov 12, 2023

A temporary "reference holder" variable that stores a function result may be attached to a reference cycle and therefore never freed.

type T = struct {
        next: ^T
}

fn foo(n: T): T {
        n.next = &n
        return n
}

fn bar() {
        foo(T{})
}                      // Runtime error: Pointer to a local variable escapes from the function

fn main() {
        bar()
}
@vtereshkov vtereshkov added bug Something isn't working enhancement New feature or request labels Nov 12, 2023
@skejeton
Copy link
Contributor

Isn't this related to #200

@vtereshkov
Copy link
Owner Author

@skejeton I think you mean #199. Yes, it's related, but not the same. There are many ways to produce a reference cycle involving a local variable. What distinguishes the current issue is that a user cannot even see this variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants