[BUG][DUMB USER] Refactoring Browser

John Brant brant at refactory.com
Fri Oct 25 23:53:05 UTC 2002


> From: squeak-dev-admin at lists.squeakfoundation.org [mailto:squeak-dev-
> admin at lists.squeakfoundation.org] On Behalf Of David Farber
> 
> [BUG]
> I've got the following method that I'd like to break up by applying
> Extract Method.
> 
> renderOn: html
> 
>   "Extract to 'self initMessage.'"
>   "Note: 'message' is an instance variable."
>   | mboxStream |
>   [mboxStream := FileStream fileNamed: 'HOS.mbx'.
>   message := RFC822Message fromMBOX: mboxStream.]
>     ensure: [mboxStream close].
> 
>   ...
> 
> When I try to extract the first block, I get an error: "Cannot extract
> assignment if read before written." This doesn't make sense as I don't
see
> anything that is getting read before written.

It is complaining about mboxStream. You could define an #ensure: method
that evaluates the argument block before the receiver block, so the
reference to mboxStream in the argument block would read the value
before it was written. Or, more likely, the #fileNamed: message raises
an error and causes the "mboxStream close" to be run without mboxStream
ever being assigned. You should move the assignment of mboxStream
outside the block.


John Brant





More information about the Squeak-dev mailing list