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

ICE: Default type parameter that references Self in an object type #18956

Closed
nikomatsakis opened this issue Nov 14, 2014 · 1 comment
Closed
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@nikomatsakis
Copy link
Contributor

This example causes an ICE:

#![feature(default_type_params)]

trait Foo<T=Self> {
    fn method(&self);
}

fn foo(x: &Foo) { }

fn main() { }

yields

<anon>:7:12: 7:15 error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Self) substs=Substs[types=[[];[];[];[]], regions=[[];[];[];[]]]

This is because, in an object type, the self parameter slot is empty, so the substitution of the default fails. I'm not 100% sure what's the best way to fix this. We could make the substitution report a proper error rather than ICE; perhaps that's best.

It is debatable whether such a trait ought to be object safe, but it seems harmless, if pointless, since the Self type winds up being revealed.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 4, 2015

not sure if this is the same or a new bug with the same symptom:

use std::ops::Add;

fn main() {
    let x = 5;
    let y = x as Add;
}

yields

<anon>:5:18: 5:21 error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Self) substs=Substs[types=[[];[];[]], regions=[[];[];[]]]

And even funkier:

use std::ops::Add;

fn main() {
    let x = 5;
    let y = x as Add<i32>;
}

says that the error is in the use line, not in the let y line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants