Fuel icon indicating copy to clipboard operation
Fuel copied to clipboard

Double replacements cause unexpected results

Open GoogleCodeExporter opened this issue 10 years ago • 12 comments

I had the thought that maybe using a double dynamic subsitution (map x to y and 
map y to x) might cause an endless loop, so I wrote a test. The good news: no 
endless loop. The bad news: the result is not quite what I expected:

testDoubleReplaceEndlessLoop
    | result |
    self analyzer 
        when: [ :x | FLPair == x ] substituteBy: [ :x | FLWeakClassMock ];
        when: [ :x | FLWeakClassMock == x ] substituteBy: [ :x | FLPair ].

    result := self resultOfSerializeAndMaterialize: {FLPair. FLWeakClassMock}.

    self assert: result class equals: Array.
    self assert: result size equals: 2.
    self assert: result first equals: FLWeakClassMock. "this line will fail"
    self assert: result second equals: FLPair


"result" will be {FLPair. FLPair} instead of the expected {FLWeakClassMock. 
FLPair}

This is certainly not an important issue but we should at least decide if we 
want to do anything about it (maybe document the limit of dynamic substitution 
in this case)

Original issue reported on code.google.com by [email protected] on 24 Feb 2013 at 2:55

GoogleCodeExporter avatar Mar 24 '15 16:03 GoogleCodeExporter

Thanks Max

Original comment by [email protected] on 24 Feb 2013 at 6:25

GoogleCodeExporter avatar Mar 24 '15 16:03 GoogleCodeExporter

HI max. I don't agreee with this one. I would expect  {FLPair. FLPair}.
All conditions block closures are evaluated (and in order). Maybe we should 
document this in the webpage?

Maybe we can add another message:  #when: ifNotAlreadyASubstituteSubstituteBy:
which checks if then object is already a subsitute does nothing and if not, 
performs the substitution?

Original comment by marianopeck on 24 Feb 2013 at 7:38

GoogleCodeExporter avatar Mar 24 '15 16:03 GoogleCodeExporter

Hi Mariano, I understand. I don't have a clear position about this...

Original comment by [email protected] on 24 Feb 2013 at 8:16

GoogleCodeExporter avatar Mar 24 '15 16:03 GoogleCodeExporter

Yes, I see your point. From a technical point of view this makes sense but it's 
confusing semantically. 

Personally, I figure that documenting this should be enough, it's an edge case 
anyhow. To implement Mariano's suggested method, there might be quite a few 
changes involved.

Original comment by [email protected] on 24 Feb 2013 at 9:16

GoogleCodeExporter avatar Mar 24 '15 16:03 GoogleCodeExporter

Sure it is that complicated?  Cannot be just send #isSubstitute: and do nothing 
when anserwing true?

Original comment by marianopeck on 25 Feb 2013 at 12:21

GoogleCodeExporter avatar Mar 24 '15 16:03 GoogleCodeExporter

forgot to said isSubstitute: is already implemented

Original comment by marianopeck on 25 Feb 2013 at 12:21

GoogleCodeExporter avatar Mar 24 '15 16:03 GoogleCodeExporter

This issue has been automatically marked as stale because it has not had recent activity. It will remain open but will probably not come into focus. If you still think this should receive some attention, leave a comment. Thank you for your contributions.

stale[bot] avatar May 18 '21 20:05 stale[bot]

Should test this before closing.

theseion avatar Oct 30 '21 17:10 theseion

This issue has been automatically marked as stale because it has not had recent activity. It will remain open but will probably not come into focus. If you still think this should receive some attention, leave a comment. Thank you for your contributions.

stale[bot] avatar Dec 29 '21 18:12 stale[bot]

Not stale.

theseion avatar Jan 02 '22 14:01 theseion

This issue has been automatically marked as stale because it has not had recent activity. It will remain open but will probably not come into focus. If you still think this should receive some attention, leave a comment. Thank you for your contributions.

stale[bot] avatar Mar 03 '22 16:03 stale[bot]

Not stale

theseion avatar Mar 04 '22 06:03 theseion