[FIX] Interval class>>newFrom:

Richard A. O'Keefe ok at cs.otago.ac.nz
Fri May 31 05:48:00 UTC 2002


In Squeak 3.0.1, try
   Interval newFrom: (1 to: 1)
You expect a fresh copy of (1 to: 1).  You GET a division by 0.
This is because the implementation starts

   | newInterval |

   newInterval := self from: aCollection first to: aCollection last
      by: (aCollection last - aCollection first) // (aCollection size - 1).

If aCollection size = 0, this errs instead of returning an empty Interval.
If aCollection size = 1, this gets a divide-by-zero.

Instead, it should read

    | newInterval n |

    (n := aCollection size) <= 1 ifTrue: [
	n = 0 ifTrue: [^self from: 1 to: 0].
	^self from: aCollection first to: aCollection last].
    newInterval := self from: aCollection first to: aCollection last
	by: (aCollection last - aCollection first) // (n - 1).

Has this already been fixed in 3.2?



More information about the Squeak-dev mailing list