Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface narrowings don't yet work #115

Closed
jyasskin opened this issue Jul 17, 2010 · 6 comments
Closed

Interface narrowings don't yet work #115

jyasskin opened this issue Jul 17, 2010 · 6 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)

Comments

@jyasskin
Copy link
Contributor

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".)

@graydon
Copy link
Contributor

graydon commented Jul 17, 2010

The mechanism I have sketched but only partly implemented for this would be 'let base b = d as base;', but it doesn't work yet. Most of the machinery is there, it's just incomplete.

When you say "an explicit cast crashes the compiler", what notation were you using for this?

@jyasskin
Copy link
Contributor Author

I was trying
let base b = base(d);
by analogy with uint(3).

@graydon
Copy link
Contributor

graydon commented Jan 27, 2011

Shifted to rustc.

@ghost ghost assigned lkuper May 26, 2011
@lkuper
Copy link
Contributor

lkuper commented Aug 9, 2011

What's the status of this issue with regard to the current state of rustc and the object system?

lkuper added a commit that referenced this issue Aug 16, 2011
@lkuper
Copy link
Contributor

lkuper commented Aug 16, 2011

Just pushed an xfail'd test for this issue. The error we're getting now is:

../rust/src/test/run-pass/interface-narrowing.rs:18:15:18:24: error: non-scalar cast: <T1> as obj {
    fn foo();
}
../rust/src/test/run-pass/interface-narrowing.rs:18   let b:base = d as base;
                                                                   ^~~~~~~~~

I'm un-assigning myself from this one and marking it as unassigned since, realistically speaking, I don't think I'll have time to handle it in the next four days. It's up for grabs...

mbrubeck pushed a commit to mbrubeck/rust that referenced this issue Oct 17, 2011
…st attempted in issue rust-lang#115, downgrade bug to an err in type.ml so you get a better message.
@marijnh
Copy link
Contributor

marijnh commented Jan 13, 2012

Objs are gone. Closing.

@marijnh marijnh closed this as completed Jan 13, 2012
oli-obk pushed a commit to oli-obk/rust that referenced this issue Jul 19, 2017
fix turning function items into closure trait objects
kazcw pushed a commit to kazcw/rust that referenced this issue Oct 23, 2018
* Add _mm_store* intrinsics and _mm_move_ss

* Fix Win64 & Linux i586 failures

* Make i586 codegen happy without breaking x86_64
dlrobertson pushed a commit to dlrobertson/rust that referenced this issue Nov 29, 2018
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Feb 1, 2022
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
jaisnan pushed a commit to jaisnan/rust-dev that referenced this issue Oct 30, 2024
These are safety abstractions that are auto-generated via script. Add
minimum contract for now.

Note: I tried adding a slightly tighter post-condition, but Kani takes a
long time to solve them. This may be an interesting test for other tools
later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)
Projects
None yet
Development

No branches or pull requests

4 participants