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 with trait inheritance/generics #4208

Closed
brendanzab opened this issue Dec 17, 2012 · 9 comments
Closed

ICE with trait inheritance/generics #4208

brendanzab opened this issue Dec 17, 2012 · 9 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries A-traits Area: Trait system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@brendanzab
Copy link
Member

numeric.rs

#[link(name = "numeric",
       vers = "0.1")];
#[crate_type = "lib"];

pub trait Trig<T> {
    pure fn sin(&self) -> T;
}

pub pure fn sin<T:Trig<R>, R>(theta: &T) -> R { theta.sin() }

pub trait Angle<T>: Trig<T> {}

main.rs

extern mod numeric;
use numeric::*;

fn foo<T, A:Angle<T>>(theta: A) -> T { sin(&theta) }

fn main() {}
$ rustc numeric.rs                           
warning: no debug symbols in executable (-arch x86_64)
$ RUST_LOG=rustc=1,::rt::backtrace rustc -L . main.rs
rust: task failed at 'Key not found in table: 28', /usr/local/src/rust/src/librustc/rustc.rc:1
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /usr/local/src/rust/src/librustc/rustc.rc:481
rust: domain main @0x7fa62380bc10 root task failed
rust: task failed at 'killed', /usr/local/src/rust/src/libcore/task/mod.rs:570
@ghost ghost assigned brson Dec 17, 2012
@brson
Copy link
Contributor

brson commented Dec 18, 2012

There are at least two problems here. The first is that the order in which type parameters are specified appears to be significant. This test fails:

pub trait Trig<T> {
    pure fn sin(&self) -> T;
}

pub trait Angle<T>: Trig<T> {}

pub pure fn sin<A:Angle<R>, R>(theta: &A) -> R { theta.sin() }

fn foo<R, A:Angle<R>>(theta: A) -> R { sin(&theta) }

impl int: Trig<int> {
    pure fn sin(&self) -> int { 10 }
}

impl int: Angle<int> {
}

fn main() {
    assert foo(0) == 10;
}

but if you switch the type parameter order on sin to <R, A:Angle<R> to match foo it works.

The second is some cross-crate issue with inheritance.

@brson
Copy link
Contributor

brson commented Dec 18, 2012

My above example is a different problem, since it makes sin have a bound of <T:Angle> instead of <T:Trig>. I'm coming up with a lot of variations that fail in different ways. I'll open another issue.

@ghost ghost assigned catamorphism Jan 24, 2013
@brendanzab
Copy link
Member Author

@catamorphism (nag nag)

@catamorphism
Copy link
Contributor

This ICEs with a different error now, but still ICEs.

@catamorphism
Copy link
Contributor

Unfortunately, I got derailed and this won't be done for 0.6. De-milestoning.

@catamorphism
Copy link
Contributor

This compiles now. I'll check in the test case.

@msullivan
Copy link
Contributor

So is this fixed?

@catamorphism
Copy link
Contributor

(bug triage) Huh, I wonder whether I checked in the test case. I'll look at that tomorrow.

@catamorphism
Copy link
Contributor

#9233 will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-traits Area: Trait system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants