From 4cad58c4645c7e2247e0655d4c1d7d70ae75339b Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 15 Sep 2012 12:29:36 -0700 Subject: [PATCH] Fix broken assertion in regionck for code like (a[])() --- src/rustc/middle/typeck/check/regionck.rs | 7 +++---- src/test/run-pass/call-closure-from-overloaded-op.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 src/test/run-pass/call-closure-from-overloaded-op.rs diff --git a/src/rustc/middle/typeck/check/regionck.rs b/src/rustc/middle/typeck/check/regionck.rs index 1eedb572d2c..d77bc7c3dda 100644 --- a/src/rustc/middle/typeck/check/regionck.rs +++ b/src/rustc/middle/typeck/check/regionck.rs @@ -183,16 +183,15 @@ fn visit_expr(expr: @ast::expr, &&rcx: @rcx, v: rvt) { // `constrain_auto_ref()` on all exprs. But that causes a // lot of spurious errors because of how the region // hierarchy is setup. - let tcx = rcx.fcx.tcx(); if rcx.fcx.ccx.method_map.contains_key(callee.id) { match callee.node { ast::expr_field(base, _, _) => { constrain_auto_ref(rcx, base); } _ => { - tcx.sess.span_bug( - callee.span, - ~"call of method that is not a field"); + // This can happen if you have code like + // (x[0])() where `x[0]` is overloaded. Just + // ignore it. } } } else { diff --git a/src/test/run-pass/call-closure-from-overloaded-op.rs b/src/test/run-pass/call-closure-from-overloaded-op.rs new file mode 100644 index 00000000000..d145a8bfd70 --- /dev/null +++ b/src/test/run-pass/call-closure-from-overloaded-op.rs @@ -0,0 +1,9 @@ +use dvec::DVec; + +fn foo() -> int { 22 } + +fn main() { + let x = DVec::<@fn() -> int>(); + x.push(foo); + assert (x[0])() == 22; +} \ No newline at end of file