diff --git a/loopy/check.py b/loopy/check.py
index baef5d37f4adc993d55848faf1dce11f74a75bba..107aa6a2debc476702459382422fdc77bb2e6278 100644
--- a/loopy/check.py
+++ b/loopy/check.py
@@ -254,6 +254,12 @@ class _AccessCheckMapper(WalkMapper):
 
                 access_range = access_map.range()
 
+                if dims != len(shape):
+                    raise RuntimeError("subscript to '%s' in '%s' has the wrong "
+                            "number of indices (got: %d, expected: %d)" % (
+                                expr.aggregate.name, expr,
+                                dims, len(shape)))
+
                 shape_domain = isl.BasicSet.universe(access_range.get_space())
                 for idim in xrange(dims):
                     from loopy.isl_helpers import make_slab