Object>>#at:put: reports improper store when everything seems fine

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

Object>>#at:put: reports improper store when everything seems fine

André Wendt-3
 
Hi,

I just stumble upon this: Object>>#at:put: calls <primitive:61>. If that
fails, the following lines read

index isInteger ifTrue:
        [self class isVariable
                ifTrue: [(index >= 1 and: [index <= self size])
                        ifTrue: [self errorImproperStore]

Why is it an improper store if the index is an integer, the receiver
class is variable, and the index is within bounds? Someone please
enlighten me...

(If this is merely reporting "there was an error in the primitive
although everything's alright", then I feel the message should be
something other than "Improper store into indexable object".)

Thanks,
André
Reply | Threaded
Open this post in threaded view
|

Re: Object>>#at:put: reports improper store when everything seems fine

Andreas.Raab
 
André Wendt wrote:

> I just stumble upon this: Object>>#at:put: calls <primitive:61>. If that
> fails, the following lines read
>
> index isInteger ifTrue:
> [self class isVariable
> ifTrue: [(index >= 1 and: [index <= self size])
> ifTrue: [self errorImproperStore]
>
> Why is it an improper store if the index is an integer, the receiver
> class is variable, and the index is within bounds? Someone please
> enlighten me...

Because it's the only failure mode that's left. It happens when you
create non-pointer subclasses, for example:

Object variableWordSubclass: #MyWordArray
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Sample-Objects'

and now:

wa := MyWordArray new: 10.
wa at: 1 put: 0. "works"
wa at: 2 put: nil. "fails"
wa at: 3 put: -1. "fails"
wa at: 4 put: 16r100000000. "fails"
wa at: 5 put: Smalltalk. "fails"

etc.

> (If this is merely reporting "there was an error in the primitive
> although everything's alright", then I feel the message should be
> something other than "Improper store into indexable object".)

Think about this for a second. What possible other failure mode could
there be in the at:put: primitive?

Cheers,
   - Andreas
Reply | Threaded
Open this post in threaded view
|

Re: Object>>#at:put: reports improper store when everything seems fine

André Wendt-3
 
Andreas Raab wrote:

>
> André Wendt wrote:
>> I just stumble upon this: Object>>#at:put: calls <primitive:61>. If that
>> fails, the following lines read
>>
>> index isInteger ifTrue:
>>     [self class isVariable
>>         ifTrue: [(index >= 1 and: [index <= self size])
>>             ifTrue: [self errorImproperStore]
>>
>> Why is it an improper store if the index is an integer, the receiver
>> class is variable, and the index is within bounds? Someone please
>> enlighten me...
>
> Because it's the only failure mode that's left. It happens when you
> create non-pointer subclasses, for example:
>
> Object variableWordSubclass: #MyWordArray
>     instanceVariableNames: ''
>     classVariableNames: ''
>     poolDictionaries: ''
>     category: 'Sample-Objects'
>
> and now:
>
> wa := MyWordArray new: 10.
> wa at: 1 put: 0. "works"
> wa at: 2 put: nil. "fails"
> wa at: 3 put: -1. "fails"
> wa at: 4 put: 16r100000000. "fails"
> wa at: 5 put: Smalltalk. "fails"
>
> etc.
>
>> (If this is merely reporting "there was an error in the primitive
>> although everything's alright", then I feel the message should be
>> something other than "Improper store into indexable object".)
>
> Think about this for a second. What possible other failure mode could
> there be in the at:put: primitive?

I guess you're right. It really *is* the only failure mode left.

Best,
André