> On Apr 15, 2018, at 9:42 AM, Ben Coman <[email protected]> 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?
In general one would need to look at the implementor to know which blocks are
always evaluated and in what order. For example, someone could have defined
whileNil: as:
whileNil: aBlock
aBlock value
In this case, it isn’t a false positive since the "x := nil” is never executed
and the first use of “x” is the “x ifNil: …”.
> Perhaps only for common looping idioms?
It does look for common looping idioms. It treats the four whileTrue/False
messages different than normal messages. It also treats
ifTrue:ifFalse:/ifFalse:ifTrue: messages differently. #whileNil: isn’t what I
call a common looping idiom as it seems to have been added in 2007 (about 13
years after the read before written tester was written), and has 0 senders in
my image.
I think a better change would be adding knowledge about and:/or: combined with
ifTrue:, whileTrue:, etc. For example,
(self someCondition and: [(x := self value) > 0]) ifTrue: [Transcript
show: x printString]
In this case, x is reported as potentially read before written, but it can’t
be.
John Brant