On 04/15/2018 07:42 AM, Ben Coman wrote:
> The greater prominence of Critiques in Calypso 
> encourages me to try to clean them out.
>
> I bumped into a false positive "Temporaries read before written."
> that I've condensed to the following example.
>
>     test
>         |x|
>         [ x := nil ] whileNil: [ x ifNil: [ x := 1] ]
>
> Now before I log an Issue, is it feasible to be able to recognise this?
> Perhaps only for common looping idioms?

In this example, the first runtime reference to x is to send it #ifNil:.
So technically, x *is* being read before being written, at least if you
count sending it a message as "reading" (which seems a reasonable
interpretation to me).
>
> Anyway, the workaround is simple enough...
>     test
>         |x|
>         x := nil. "silence critiques"
>         [ x := nil ] whileNil: [ x ifNil: [ x := 1] ]
Probably not a terrible idea to be explicit about initializing to nil,
thereby revealing the developer's intent that this variable be nil
rather than relying on the default initialization to nil.

So I'd lean towards leaving the critique as-is. If a developer knows
what they did was safe, they can either ignore the critique, exclude the
critique, or put in the explicit initialization to nil. I think I prefer
explicit initialization.

Regards,
-Martin

Reply via email to