Check early on in typeck that types being implemented are actually iface types

Closes #2330.
This commit is contained in:
Tim Chevalier 2012-05-03 10:10:12 -07:00
parent 74096a79d8
commit d8f28be753
2 changed files with 25 additions and 5 deletions

View file

@ -559,20 +559,27 @@ fn ast_path_to_ty<AC: ast_conv, RS: region_scope copy>(
/*
Instantiates the path for the given iface reference, assuming that
it's bound to a valid iface type. Returns the def_id for the defining
iface
iface. Fails if the type is a type other than an iface type.
*/
fn instantiate_iface_ref(ccx: @crate_ctxt, t: @ast::iface_ref,
rp: ast::region_param)
-> (ast::def_id, ty_param_substs_and_ty) {
let sp = t.path.span, err = "can only implement interface types",
sess = ccx.tcx.sess;
alt lookup_def_tcx(ccx.tcx, t.path.span, t.id) {
ast::def_ty(t_id) {
(t_id, ast_path_to_ty(ccx, type_rscope(rp), t_id, t.path, t.id))
let tpt = ast_path_to_ty(ccx, type_rscope(rp), t_id, t.path, t.id);
alt ty::get(tpt.ty).struct {
ty::ty_iface(*) {
(t_id, tpt)
}
_ { sess.span_fatal(sp, err); }
}
}
_ {
ccx.tcx.sess.span_fatal(
t.path.span,
"can only implement interface types");
sess.span_fatal(sp, err);
}
}
}

View file

@ -0,0 +1,13 @@
enum chan { }
iface channel<T> {
fn send(v: T);
}
// `chan` is not an iface, it's an enum
impl of chan for int { //! ERROR can only implement interface types
fn send(v: int) { fail }
}
fn main() {
}