Skip to content

Polymorphic Recursion Causing Stack Overflow #18962

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

Closed
jozefg opened this issue Nov 14, 2014 · 1 comment
Closed

Polymorphic Recursion Causing Stack Overflow #18962

jozefg opened this issue Nov 14, 2014 · 1 comment

Comments

@jozefg
Copy link

jozefg commented Nov 14, 2014

The following causes rustc to keel over

enum Tree<A> {
    Leaf(A),
    Node(Box<Tree<(A, A)>>)
}

fn size<A>(t : &Tree<A>) -> int {
    match t {
        &Leaf(_) => 1,
        &Node(box ref t) => size(t)
    }
}

fn main () {}

// task 'rustc' has overflowed its stack
// Compilation illegal instruction (core dumped) at Fri Nov 14 18:04:13

However it handles the actual declaration fine, the issue seems to be due to the polymorphic recursion in size. This compiles fine

enum Tree<A> {
    Leaf(A),
    Node(Box<Tree<(A, A)>>)
}

fn main () {}

My rustc information is

rustc 0.13.0-nightly (5745e4195 2014-11-12 22:57:16 +0000)
binary: rustc
commit-hash: 5745e419502d753deb3f42026fa35e015bc5d3fb
commit-date: 2014-11-12 22:57:16 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly
@huonw
Copy link
Member

huonw commented Nov 14, 2014

Dupe of #4363. Thanks for filing!

@huonw huonw closed this as completed Nov 14, 2014
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

2 participants