Commit f0b44db8 authored by rschlatte@1c010e3e-69d0-11dd-93a8-456734b0d56f's avatar rschlatte@1c010e3e-69d0-11dd-93a8-456734b0d56f
Browse files

Refine #14135: now with less misleading error message

- The upper bound of the INTEGER type is inclusive - ask for an integer
  between 0 and n-1

- If the object has no slots at all, raise a program-error instead of a
  type-error

- If the location argument has the wrong type, ask for an integer, not a
  more fancy type
parent a49489a0
......@@ -429,27 +429,26 @@ public class StandardObject extends LispObject
{
final StandardObject instance = checkStandardObject(first);
final int index;
if (second instanceof Fixnum)
{
index = ((Fixnum)second).value;
}
else
{
return type_error(second,
list(Symbol.INTEGER, Fixnum.ZERO,
Fixnum.getInstance(instance.slots.length)));
}
if (second instanceof Fixnum) {
index = ((Fixnum)second).value;
} else {
return type_error(second, Symbol.INTEGER);
}
LispObject value;
try
{
value = instance.slots[index];
}
catch (ArrayIndexOutOfBoundsException e)
{
try {
value = instance.slots[index];
} catch (ArrayIndexOutOfBoundsException e) {
if (instance.slots.length > 0)
return type_error(second,
list(Symbol.INTEGER, Fixnum.ZERO,
Fixnum.getInstance(instance.slots.length)));
}
Fixnum.getInstance(instance.slots.length - 1)));
else
return error(new ProgramError("The object "
+ instance.princToString() +
" has no slots."));
}
// We let UNBOUND_VALUE escape here, since invoking
// standard-instance-access on an unbound slot has undefined
// consequences (AMOP pg. 239), and we use this behavior to
......@@ -478,17 +477,20 @@ public class StandardObject extends LispObject
if (second instanceof Fixnum) {
index = ((Fixnum)second).value;
} else {
return type_error(second,
list(Symbol.INTEGER, Fixnum.ZERO,
Fixnum.getInstance(instance.slots.length)));
return type_error(second, Symbol.INTEGER);
}
try {
instance.slots[index] = third;
} catch (ArrayIndexOutOfBoundsException e) {
return type_error(second,
list(Symbol.INTEGER, Fixnum.ZERO,
Fixnum.getInstance(instance.slots.length)));
if (instance.slots.length > 0)
return type_error(second,
list(Symbol.INTEGER, Fixnum.ZERO,
Fixnum.getInstance(instance.slots.length - 1)));
else
return error(new ProgramError("The object "
+ instance.princToString() +
" has no slots."));
}
return third;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment