Double replacements cause unexpected results
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
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
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
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
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
forgot to said isSubstitute: is already implemented
Original comment by marianopeck on 25 Feb 2013 at 12:21
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.
Should test this before closing.
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.
Not stale.
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.
Not stale