about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-08-06 19:16:44 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-08-06 19:17:44 -0700
commitf3b2296ee4d2cdd902207cdc52b35dbe4e50427c (patch)
tree1acf2f3bfada3b5f51ac0e6258eaf2e91a642fc5 /src
parentaacd18f4ed860420cb89cd103a9832ef47e838f3 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/rustc/middle/trans/impl.rs6
-rw-r--r--src/test/run-pass/issue-2935.rs24
2 files changed, 30 insertions, 0 deletions
diff --git a/src/rustc/middle/trans/impl.rs b/src/rustc/middle/trans/impl.rs
index 979bb6e847a..066c1bedba2 100644
--- a/src/rustc/middle/trans/impl.rs
+++ b/src/rustc/middle/trans/impl.rs
@@ -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)
       }
     }
diff --git a/src/test/run-pass/issue-2935.rs b/src/test/run-pass/issue-2935.rs
new file mode 100644
index 00000000000..36ad03a0df3
--- /dev/null
+++ b/src/test/run-pass/issue-2935.rs
@@ -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
+}