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 Default Methods on Traits #5139

Closed
mitsuhiko opened this Issue Feb 27, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@mitsuhiko
Contributor

mitsuhiko commented Feb 27, 2013

The following code is currently causing an internal compiler error:

trait Iterable<T, I:Iterator<T>> {
    fn get_iterator(&self) -> I;
}

trait Iterator<T> {
    fn next(&mut self) -> Option<&self/T>;
    fn each(&mut self, f: fn(&T) -> bool) {
        loop {
            match self.next() {
                None => { break; }
                Some(ref x) => { if !f(x) { break; } }
            }
        }
    }
}

struct VectorIterator<T> {
    priv vec: &[T],
    priv pos: uint,
    priv end: uint,
}

impl <T> Iterable<T, VectorIterator<T>> for &[T] {
    fn get_iterator(&self) -> VectorIterator/&self<T> {
        VectorIterator { vec: *self, pos: 0, end: vec::len(*self) }
    }
}

impl <T> Iterator<T> for VectorIterator<T> {
    fn next(&mut self) -> Option<&self/T> {
        if self.pos >= self.end {
            None
        } else {
            let x = self.pos;
            self.pos += 1;
            Some(&self.vec[x])
        }
    }
}

fn main() {
    let v = ["foo", "bar", "baz"];
    for v.get_iterator().each |&x| {
        io::println(fmt!("> %s", x));
    }
}

The exception:

rust: task failed at 'index out of bounds: the len is 0 but the index is 0', /Users/mitsuhiko/Development/rust/src/librustc/middle/ty.rs:1424

The line in question is the ty_param(p) => subst.tps[p.idx] one: https://github.com/mozilla/rust/blob/ba7a8706609a96080f75de57ab0af7ac86dbb583/src/librustc/middle/ty.rs#L1425

@mitsuhiko

This comment has been minimized.

Show comment
Hide comment
@mitsuhiko

mitsuhiko Feb 27, 2013

Contributor

(Remove the .each [and the usage of .each which however is not causing the issue] and it compiles.)

Contributor

mitsuhiko commented Feb 27, 2013

(Remove the .each [and the usage of .each which however is not causing the issue] and it compiles.)

@catamorphism

This comment has been minimized.

Show comment
Hide comment
@catamorphism

catamorphism Apr 29, 2013

Contributor

Can't reproduce with 7b7a0fc (the code does elicit several type errors, some of which were initially related to obsolete lifetime syntax, but even after I fixed those I still got type errors). Closing, reopen if you have an up-to-date example.

Contributor

catamorphism commented Apr 29, 2013

Can't reproduce with 7b7a0fc (the code does elicit several type errors, some of which were initially related to obsolete lifetime syntax, but even after I fixed those I still got type errors). Closing, reopen if you have an up-to-date example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment