changeset 14127:b5e819930fd5 stable

Give friendlier error message when indexing with default i or j (bug #35157) * ov-complex.h (index_vector): Override to give a friendlier error message. * test_index.m: Test for the new behaviour.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 29 Dec 2011 23:41:13 -0500
parents 32debc2e08bb
children 6258e5cd0f56
files src/ov-complex.h test/test_index.m
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ov-complex.h
+++ b/src/ov-complex.h
@@ -79,6 +79,15 @@
   octave_value do_index_op (const octave_value_list& idx,
                             bool resize_ok = false);
 
+  // Use this to give a more specific error message
+  idx_vector index_vector (void) const
+  {
+    error (
+           "attempted to use a complex scalar as an index\n"
+           "       (forgot to initialize i or j?)");
+    return idx_vector ();
+  }
+
   octave_value any (int = 0) const
     {
       return (scalar != Complex (0, 0)
--- a/test/test_index.m
+++ b/test/test_index.m
@@ -349,3 +349,9 @@
 %! assert (a, reshape (1:4,[1,1,1,4]));
 
 %!error (a(1:2,1:2) = 1:4)
+
+%!shared x
+%! x = 1:5;
+%!error <attempted to use a complex scalar as an index> x(i)
+%!error <attempted to use a complex scalar as an index> x(j)
+%!error <attempted to use a complex scalar as an index> x(1+i)