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

View: New views
3 Messages — Rating Filter:   Alert me  

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

by André Wendt-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 
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é

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

by Andreas Raab :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 
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

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

by André Wendt-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 
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é
LightInTheBox - Buy quality products at wholesale price