Skip to content

ICE with static methods #4165

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
brendanzab opened this issue Dec 12, 2012 · 3 comments
Closed

ICE with static methods #4165

brendanzab opened this issue Dec 12, 2012 · 3 comments
Assignees
Milestone

Comments

@brendanzab
Copy link
Member

pub struct Vec2<T> { x: T, y: T }

pub impl<T:Copy Number> Vec2<T> {
    static pure fn zero() -> Vec2<T> {
        let _0 = Number::from(0f);    // FIXME: causes ICE
        Vec2 { x: _0, y: _0 }
    }
}

pub trait Number: NumConv {
    static pure fn from<T:Number>(n: T) -> self;
}

pub impl float: Number {
    static pure fn from<T:Number>(n: T) -> float { n.to_float() }
}

pub trait NumConv {
    pure fn to_float(&self) -> float;
}

pub impl float: NumConv {
    pure fn to_float(&self) -> float { *self }
}

fn main() {
    let _: Vec2<float> = Vec2::zero();
}
 $ RUST_LOG=rustc=1,::rt::backtrace rustc src/vec.rs
rust: task failed at 'index out of bounds: the len is 1 but the index is 1', /usr/local/src/rust/src/librustc/middle/trans/common.rs:1327
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:483
rust: domain main @0x7f8a0c800010 root task failed
rust: task failed at 'killed', /usr/local/src/rust/src/libcore/task/mod.rs:630

Context:

@ghost ghost assigned brson Dec 12, 2012
@brson
Copy link
Contributor

brson commented Dec 13, 2012

Redefining Number like this makes it work

pub trait Number: NumConv {
    static pure fn from<T:NumConv>(n: T) -> self;
}

With T:NumConv instead of T:Number. Somehow trans is not receiving the proper number of vtables for T.

@brson
Copy link
Contributor

brson commented Dec 13, 2012

Reduced further

pub trait Number: NumConv {
    static pure fn from<T:Number>(n: T) -> self;
}

pub impl float: Number {
    static pure fn from<T:Number>(n: T) -> float { n.to_float() }
}

pub trait NumConv {
    pure fn to_float(&self) -> float;
}

pub impl float: NumConv {
    pure fn to_float(&self) -> float { *self }
}

fn main() {
    let _: float = Number::from(0.0f);
}

@brendanzab
Copy link
Member Author

Ahh cheers!

At least I now have a good interim solution. :)

@brson brson closed this as completed in 6047dd3 Dec 13, 2012
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