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:
@@ -14,6 +14,9 @@ import lib::llvm::llvm;
|
|||||||
import lib::llvm::{ValueRef, TypeRef};
|
import lib::llvm::{ValueRef, TypeRef};
|
||||||
import lib::llvm::llvm::LLVMGetParam;
|
import lib::llvm::llvm::LLVMGetParam;
|
||||||
import std::map::hashmap;
|
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,
|
fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
|
||||||
methods: ~[@ast::method], tps: ~[ast::ty_param]) {
|
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) => {
|
typeck::method_trait(_, off) => {
|
||||||
let {bcx, val} = trans_temp_expr(bcx, self);
|
let {bcx, val} = trans_temp_expr(bcx, self);
|
||||||
let fty = node_id_type(bcx, callee_id);
|
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)
|
trans_trait_callee(bcx, val, fty, off)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/test/run-pass/issue-2935.rs
Normal file
24
src/test/run-pass/issue-2935.rs
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user