Skip to content

Direct cast to a polymorphic trait type is not supported directly #3635

Closed
@ahmadsalim

Description

@ahmadsalim

It seems that one is not able to cast to a polymorphic type directly e.g.

extern mod std;
fn main () {
  let table : std::map::HashMap<int, int> = std::map::HashMap::<int, int>();
  (table as std::map::Map<int,int>).insert(123, 1233);
  io::println(table.get(123).to_str());
}

does not work, but

extern mod std;
fn main () {
  let table : std::map::HashMap<int, int> = std::map::HashMap::<int, int>();
  (table as @std::map::Map<int,int>).insert(123, 1233);
  io::println(table.get(123).to_str());
}

does.

It might be a documentation bug if one is only allowed to cast to a trait pointer type (as it is shown in the tutorial that one can cast to Drawable trait directly), or it might be an implementation bug regarding traits with type parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions