diff --git a/firedrake/functionspaceimpl.py b/firedrake/functionspaceimpl.py index 1d3bd2bf24..ac98149549 100644 --- a/firedrake/functionspaceimpl.py +++ b/firedrake/functionspaceimpl.py @@ -195,12 +195,15 @@ def _components(self): @PETSc.Log.EventDecorator() def sub(self, i): - #bound = len(self._components) - #if i < 0 or i >= bound: - # raise IndexError("Invalid component %d, not in [0, %d)" % (i, bound)) if len(self) == 1: + bound = len(self._components) + if i < 0 or i >= bound: + raise IndexError("Invalid component %d, not in [0, %d)" % (i, bound)) return self._components[i] else: + bound = len(self) + if i < 0 or i >= bound: + raise IndexError("Invalid index %d, not in [0, %d)" % (i, bound)) return self.subfunctions[i] @utils.cached_property