Auto-deref the base expr in trans_method_callee

(specifically in the method_trait case) -- if you wrote x.f()
and x has type @T for a trait T, x wasn't getting auto-deref'ed.

This was bad.

Closes #2935
This commit is contained in:
Tim Chevalier 2012-08-06 19:16:44 -07:00
parent aacd18f4ed
commit f3b2296ee4
2 changed files with 30 additions and 0 deletions

View File

@ -14,6 +14,9 @@ import lib::llvm::llvm;
import lib::llvm::{ValueRef, TypeRef};
import lib::llvm::llvm::LLVMGetParam;
import std::map::hashmap;
import util::ppaux::{ty_to_str, tys_to_str};
import syntax::print::pprust::expr_to_str;
fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
methods: ~[@ast::method], tps: ~[ast::ty_param]) {
@ -70,6 +73,9 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
typeck::method_trait(_, off) => {
let {bcx, val} = trans_temp_expr(bcx, self);
let fty = node_id_type(bcx, callee_id);
let self_ty = node_id_type(bcx, self.id);
let {bcx, val, _} = autoderef(bcx, self.id, val, self_ty,
uint::max_value);
trans_trait_callee(bcx, val, fty, off)
}
}

View File

@ -0,0 +1,24 @@
//type t = { a: int };
// type t = { a: bool };
type t = bool;
trait it {
fn f();
}
impl of it for t {
fn f() { }
}
fn main() {
// let x = ({a: 4i} as it);
// let y = @({a: 4i});
// let z = @({a: 4i} as it);
// let z = @({a: true} as it);
let z = @(true as it);
// x.f();
// y.f();
// (*z).f();
#error["ok so far..."];
z.f(); //segfault
}