[squeak-dev] #deepCopy seems broken for IdentitySet

Stéphane Rollandin lecteur at zogotounga.net
Fri Mar 3 15:39:43 UTC 2023


Hello all,

After spending way too long on a bug in my code, I found the culprit to 
be that deep-copying an IdentitySet is not reliable. The copy may need a 
#rehash.

To see this, do

	iset := {1 at 1} asIdentitySet.
	results := Set new.
	
	100 timesRepeat: [
		dcset := iset deepCopy.
		results add: (dcset includes: dcset anyOne)].

	results "explore it"

This should show both true and false in results.

The proportion is about 2/3 false, which seems to correspond to the 
probability that #scanFor: will return a wrong index for a set of one 
element that needs a rehash, since

	{1 at 1} asIdentitySet array	

may be either one of

	{nil . nil . 1 at 1}
	{nil . 1 at 1 . nil}
	{1 at 1 . nil . nil}


This behavior has been there for ages though - so, am I missing something?

Stef


More information about the Squeak-dev mailing list