[armedbear-cvs] r14136 - trunk/abcl/src/org/armedbear/lisp
rschlatte at common-lisp.net
rschlatte at common-lisp.net
Sun Aug 26 17:37:31 UTC 2012
Author: rschlatte
Date: Sun Aug 26 10:37:30 2012
New Revision: 14136
Log:
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
Modified:
trunk/abcl/src/org/armedbear/lisp/StandardObject.java
Modified: trunk/abcl/src/org/armedbear/lisp/StandardObject.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/StandardObject.java Sun Aug 26 08:09:27 2012 (r14135)
+++ trunk/abcl/src/org/armedbear/lisp/StandardObject.java Sun Aug 26 10:37:30 2012 (r14136)
@@ -429,27 +429,26 @@
{
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 @@
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;
}
More information about the armedbear-cvs
mailing list