Skip to content

Commit

Permalink
Handle regions correctly in class ctors and dtors
Browse files Browse the repository at this point in the history
Class ctors and dtors were always getting assigned the empty region
before, which meant a reference to the "self" region in a ctor argument
got resolved to a named region called "self" rather than the class's
self region, which led to a rather confusing error message as documented
in #2502.

Closes #2502
  • Loading branch information
catamorphism committed Jun 7, 2012
1 parent 3b4cfde commit f4fb0f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/rustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,31 +369,23 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
let t_ctor =
ty::mk_fn(
tcx,
ty_of_fn_decl(ccx,
empty_rscope,
ast::proto_any,
ctor.node.dec,
none));
ty_of_fn_decl(ccx, type_rscope(rp), ast::proto_any,
ctor.node.dec, none));
write_ty_to_tcx(tcx, ctor.node.id, t_ctor);
tcx.tcache.insert(local_def(ctor.node.id),
{bounds: tpt.bounds,
rp: ast::rp_none,
rp: rp,
ty: t_ctor});
option::iter(m_dtor) {|dtor|
// Write the dtor type
let t_dtor = ty::mk_fn(
tcx,
// not sure about empty_rscope
// FIXME
ty_of_fn_decl(ccx,
empty_rscope,
ast::proto_any,
ast_util::dtor_dec(),
none));
ty_of_fn_decl(ccx, type_rscope(rp), ast::proto_any,
ast_util::dtor_dec(), none));
write_ty_to_tcx(tcx, dtor.node.id, t_dtor);
tcx.tcache.insert(local_def(dtor.node.id),
{bounds: tpt.bounds,
rp: ast::rp_none,
rp: rp,
ty: t_dtor});
};
ensure_iface_methods(ccx, it.id);
Expand Down
13 changes: 13 additions & 0 deletions src/test/run-pass/issue-2502.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class font/& {
let fontbuf: &self.[u8];

new(fontbuf: &self.[u8]) {
self.fontbuf = fontbuf;
}

fn buf() -> &self.[u8] {
self.fontbuf
}
}

fn main() { }

0 comments on commit f4fb0f9

Please sign in to comment.