Skip to content

Static methods get the wrong type in the presence of trait type parameters #7571

@msullivan

Description

@msullivan

The following code doesn't compile because map_ is assigned the wrong type.

trait vec_utils<T> {
    fn map_<U:Copy>(x: &Self, f: &fn(&T) -> U) -> ~[U];
}



impl<T> vec_utils<T> for ~[T] {
    fn map_<U:Copy>(x: &~[T], f: &fn(&T) -> U) -> ~[U] {
        let mut r = ~[];
        for x.iter().advance |elt| {
            r.push(f(elt));
        }
        r
    }
}

fn main() {
    vec_utils::map_(&~[1,2,3], |&x| x+1);
}

There is a mistake in the type parameter handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemA-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions