bugGNU Octave - Bugs: bug #50010, Index error message "error:...

 
 

bug #50010: Index error message "error: a(5): out of bound 1", et al. have bracket type match

Submitter:  Dan Sebald <sebald>
Submitted:  Tue 10 Jan 2017 03:03:46 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Patch Submitted Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 12 Mar 2019 06:15:47 PM UTC, comment #5: 

@jwe: Unfortunately, old patch does not apply cleanly.

Rik <rik5>
Group administrator
Sun 03 Mar 2019 06:43:55 AM UTC, comment #4: 

@jwe: This is quite an old bug, but you did write a patch for it.  Do you want to apply it?

Rik <rik5>
Group administrator
Tue 10 Jan 2017 05:58:05 PM UTC, comment #3: 

A lot of code hunks in the patch, but it all looks pretty straightforward.  Tested a build here and it works.  Thanks.

Dan Sebald <sebald>
Tue 10 Jan 2017 10:48:15 AM UTC, comment #2: 

The attached patch appears to do the job for me.

At the point where the exception is first thrown, we don't know the type of indexing that was used.  That's only known in the octave_cell indexing or indexed assignment methods.  So I added try/catch blocks there to set the type of indexing for the exception message that is created later.

(file #39424)

John W. Eaton <jwe>
Group administrator
Tue 10 Jan 2017 05:19:01 AM UTC, comment #1: 

This "index_exception" may be a fairly low level base class (i.e., complex_index_exception looks to be built on index_exception), and it could be that some object other than the one that created the exception displays the message.  If that is the case, perhaps it makes more sense to pass the brack type info in at the creation of the index_exception object rather than the ::message() and ::expression() member functions.

Dan Sebald <sebald>
Tue 10 Jan 2017 03:03:46 AM UTC, original submission:  

The following examples:


octave:104> clear
octave:105> a{1} = 3;
octave:106> a{2}
error: a(2): out of bound 1
octave:106> clear
octave:107> a{2,2} = 6;
octave:108> a{5,5}
error: a(5,_): but a has size 2x2


From JWE:

"Yes, the error message should definitely display the type of index that was used.  The functions in lo-array-errwarn.{h,cc} should be modified to accept a parameter that specifies the type of index, then that info should be passed at the point of the error.  I'm assuming that the type of index is available at that point.  If not, then more significant surgery will be required."

It appears that the two routines that construct this message are:


  // Common procedures of base class index_exception, thrown whenever an
  // object is indexed incorrectly, such as by an index that is out of
  // range, negative, fractional, complex, or of a non-numeric type.

  std::string
  index_exception::message (void) const
  {
    std::string msg = expression () + ": " + details ();
    return msg.c_str ();
  }

  // Show the expression that caused the error, e.g.,  "A(-1,_)",
  // "A(0+1i)", "A(_,3)".  Show how many indices come before/after the
  // offending one, e.g., (<error>), (<error>,_), or (_,<error>,...[x5]...)

  std::string
  index_exception::  // Common procedures of base class index_exception, thrown whenever an
  // object is indexed incorrectly, such as by an index that is out of
  // range, negative, fractional, complex, or of a non-numeric type.

  std::string
  index_exception::message (void) const
  {
    std::string msg = expression () + ": " + details ();
    return msg.c_str ();
  }

  // Show the expression that caused the error, e.g.,  "A(-1,_)",
  // "A(0+1i)", "A(_,3)".  Show how many indices come before/after the
  // offending one, e.g., (<error>), (<error>,_), or (_,<error>,...[x5]...)

  std::string
  index_exception::expression (void) const
  {
    std::ostringstream buf;

    if (var.empty () || var == "<unknown>")
      buf << "index ";
    else
      buf << var;

    bool show_parens = dim > 0;

    if (show_parens)
      {
        if (dim < 5)
          {
            buf << "(";

            for (octave_idx_type i = 1; i < dim; i++)
              buf << "_,";
          }
        else
          buf << "(...[x" << dim - 1 << "]...";
      }

    buf << idx ();

    if (show_parens)
      {
        if (nd - dim < 5)
          {
            for (octave_idx_type i = 0; i < nd - dim; i++)
              buf << ",_";

            if (nd >= dim)
              buf << ")";
          }
        else
          buf << "...[x" << nd - dim << "]...)";
      }

    return buf.str ();
  }
 const
  {
    std::ostringstream buf;

    if (var.empty () || var == "<unknown>")
      buf << "index ";
    else
      buf << var;

    bool show_parens = dim > 0;

    if (show_parens)
      {
        if (dim < 5)
          {
            buf << "(";

            for (octave_idx_type i = 1; i < dim; i++)
              buf << "_,";
          }
        else
          buf << "(...[x" << dim - 1 << "]...";
      }

    buf << idx ();

    if (show_parens)
      {
        if (nd - dim < 5)
          {
            for (octave_idx_type i = 0; i < nd - dim; i++)
              buf << ",_";

            if (nd >= dim)
              buf << ")";
          }
        else
          buf << "...[x" << nd - dim << "]...)";
      }

    return buf.str ();
  }


As suggested, probably the easiest thing to do is add input variables to both of these routines such as

index_exception::expression (std::string openparen, std::string closeparen) const

and use openparen in place of "(" and closeparen in place of ")".

Then compile and see where the compiler complains about function mismatch and make the changes there.  It just as efficient doing that as it is testing something like index_type.  Even more efficient would be passing just a character (i.e., make the inputs char instead of std::string), but I'm not sure if C++ has defined + operator for a string and just a character.

Dan Sebald <sebald>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #39424:  diffs.txt added by jwe (9KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by sebald (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-03 rik5 StatusNone Patch Submitted
    2017-01-10 jwe Attached File- Added diffs.txt, #39424

    Back to the top

    Powered by Savane 3.14-8eb0.
    Corresponding source code