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

Infinite loop with a self-referential class #2572

Closed
catamorphism opened this issue Jun 12, 2012 · 3 comments
Closed

Infinite loop with a self-referential class #2572

catamorphism opened this issue Jun 12, 2012 · 3 comments
Labels
A-typesystem Area: The type system

Comments

@catamorphism
Copy link
Contributor

class kitten {
    let cat: option<cat>;
    new(cat: option<cat>) {
       self.cat = cat;
    }
}

type cat = @kitten;

fn main() {}

This program causes rustc to go into an infinite loop. I'd thought the infinite loop was in infer, but it seems to instead be in trans... so I'll keep looking.

@ghost ghost assigned catamorphism Jun 12, 2012
@catamorphism
Copy link
Contributor Author

It's pretty obvious why -- type_of goes into an infinite loop since it substitutes typedefs, and then it needs to know the LLVM type of kitten in order to compute the type of kitten (since a class's type is just a struct of its fields). But not sure what to do. This should be permitted.

@catamorphism
Copy link
Contributor Author

The example compiles if I change type to enum in type cat, since then the typedef won't be substituted. I think it's bad that the original program infinite-loops, but I don't see an easy way out of it. To compute the type of the outer class kitten I need to know the types of each of its fields, and then to know the size of the cat field I need to know the type of kitten.

@pcwalton
Copy link
Contributor

Fixed. This was blocking Servo.

RalfJung added a commit to RalfJung/rust that referenced this issue Oct 4, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

2 participants