Skip to content

Questionable type inference fail using complex generics and static methods #4107

Closed
@brson

Description

@brson

Reduced from lmath. Note that I'm not sure whether this should work. Needs investigation.

fn main() {
    let id: &Mat2<float> = &Matrix::identity();
}

pub trait Index<Index,Result> { }
pub trait Dimensional<T>: Index<uint, T> { }

pub struct Mat2<T> { x: () }
pub struct Vec2<T> { x: () }

pub impl<T> Mat2<T>: Dimensional<Vec2<T>> { }
pub impl<T> Mat2<T>: Index<uint, Vec2<T>> { }

pub impl<T> Vec2<T>: Dimensional<T> { }
pub impl<T> Vec2<T>: Index<uint, T> { }

pub trait Matrix<T,V>: Dimensional<V> {
    static pure fn identity() -> self;
}

pub impl<T> Mat2<T>: Matrix<T, Vec2<T>> {
    static pure fn identity() -> Mat2<T> { fail }
}
/home/brian/dev/rust/src/test/run-pass/lmath.rs:2:26: 2:42 error: mismatched types: expected `@Index<uint,float>` but found `@Index<uint,Vec2<float>>` (expected float but found class Vec2)                         
/home/brian/dev/rust/src/test/run-pass/lmath.rs:2     let id: Mat2<float> = Matrix::identity();                                                                                                                      
                                                                            ^~~~~~~~~~~~~~~~                                                                                                                         
/home/brian/dev/rust/src/test/run-pass/lmath.rs:2:26: 2:42 error: mismatched types: expected `Vec2<float>` but found `float` (expected class Vec2 but found float)                                                   
/home/brian/dev/rust/src/test/run-pass/lmath.rs:2     let id: Mat2<float> = Matrix::identity();                                                                                                                      
                                                                            ^~~~~~~~~~~~~~~~    

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions