Skip to content

self types unsound with boxed ifaces #1994

@nikomatsakis

Description

@nikomatsakis

Currently, if a method on an iface mentions the type self, we forbid that method from being called via a boxed iface. But this restriction can be worked around by using generic types:

    iface i { fn foo() -> self<>; }
    fn foo<T:i>(v: T) -> T {
        ret v.foo();
    }
    impl of i for uint {
        fn foo() -> uint { ret self; }
    }
    fn main() {
        let x: i = 3u as i;
        let y = foo(x); // y has type i, but is in fact a uint
    }

A couple of solutions spring to mind, but on IRC we discussed saying that if an iface i includes a self type, then instances of i do not implement i.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions