Manuscript (Case [Issue]20823) _Inbox - #sum on empty array results in SubscriptOutOfBounds error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Manuscript (Case [Issue]20823) _Inbox - #sum on empty array results in SubscriptOutOfBounds error

Pharo Issue Tracker
Manuscript Notification
avatar
Adam Elston opened Case 20823: #sum on empty array results in SubscriptOutOfBounds error and assigned it to Everyone:
Bug in Project:  _Inbox: Not Spam  •  You are subscribed to this case
Version: Pharo 6.1

Minimal reproduction:
#() sum.

Expected: 0
Actual: SubscriptOutOfBounds.

The error is in the #sum method on the Array class. It chooses a sample by calling #anyOne, but as the array is empty this results in an error.

The reason I believe this should be fixed is that calling #sum on an empty array is a valid use case, particularly when using a method like #select.

E.g. (myCollection select: [:i | i meetsSomeCriteria ]) sum , where none of the values in myCollection meet the criteria.
Priority Priority: 5 – Fix If Time Status Status: Work Needed
Assigned To Assigned to: Everyone Milestone Milestone: Later

Go to Case
No longer need updates? Unsubscribe from this case.

Don't want Manuscript notifications anymore? Update your preferences.

Manuscript

_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
https://lists.gforge.inria.fr/mailman/listinfo/pharo-bugtracker