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

Segfault for programs with nested closures #178

Open
PaulBone opened this issue Jul 2, 2019 · 0 comments

Comments

@PaulBone
Copy link
Member

commented Jul 2, 2019

A program with nested closures, like

// Wrap this in a function to help the typechecker.
func lines() -> Int {
    return 4
}

func main() uses IO -> Int {
    
    func phrase1(drink : String) -> String {
        return "No more " ++ drink ++ "\n"
    }
    func make_closure(drink : String) -> func() uses IO {
        func sing(n : Int) -> String {
            if (n == 0) {
                return phrase1(drink)
            } else {
                return int_to_string(n) ++ " bottles of " ++ drink ++ "...\n" ++
                    sing(n - 1)
            }
        }
        
        func doit() uses IO {
            print!(sing(lines()))
        }
        
        return doit
    }
    
    var my_closure = make_closure("wine")
    
    my_closure!()
    
    return 0
}

Crashes with a segfault at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.