[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #50010] Index error message "error: a(5): out
From: |
Dan Sebald |
Subject: |
[Octave-bug-tracker] [bug #50010] Index error message "error: a(5): out of bound 1", et al. have bracket type match |
Date: |
Tue, 10 Jan 2017 03:03:47 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0 |
URL:
<http://savannah.gnu.org/bugs/?50010>
Summary: Index error message "error: a(5): out of bound 1",
et al. have bracket type match
Project: GNU Octave
Submitted by: sebald
Submitted on: Tue 10 Jan 2017 03:03:46 AM GMT
Category: Interpreter
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Inaccurate Result
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: dev
Operating System: Any
_______________________________________________________
Details:
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.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?50010>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #50010] Index error message "error: a(5): out of bound 1", et al. have bracket type match,
Dan Sebald <=