Skip to content

Interface narrowings don't yet work #115

Closed
@jyasskin

Description

@jyasskin

Currently:

type base =
  obj {
    fn foo();
  };
obj derived() {
  fn foo() {}
  fn bar() {}
}
fn main() {
  let derived d = derived();
  let base b = d;
}

fails to compile with:

test2.rs:11:19 - 11:20:E:Error: mismatched types: expected obj {
    fn foo() -> ();
    fn bar() -> ();
} but found obj {
    fn foo() -> ();
}

Adding an explicit cast to base crashes the compiler. The rust docs say "Such a “plain” object type can be used to describe an interface that a variety of particular objects may conform to, by supporting a superset of the methods." so I'd expect the implicit conversion to work. (On the other hand, then "any" is just "obj {}", and Graydon has said he doesn't want an implicit conversion to "any".)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions