Internal users of asOrderedCollection should be rewritten because asOrderedCollection is deprecated
Object >> asOrderedCollection
self
deprecated:
'The usage of this method is not recommended. We want to have a smaller Object api. We will remove this method in the next Pharo version.'
"Automatic transform removed. See https://github.com/pharo-project/pharo/issues/14197"
"transformWith: '`@receiver asOrderedCollection' -> 'OrderedCollection with: `@receiver'".
^ OrderedCollection with: self
We should only rewrite receivers that are not collection.
If you be nice to be able to use deprecated: anExplanationString transformWith: aRule when: conditionBlock
but I do not know the scope of conditionBlock: because we want to express
Object >> asOrderedCollection
self
deprecated:
'The usage of this method is not recommended. We want to have a smaller Object api. We will remove this method in the next Pharo version.'
transformWith: '`@receiver asOrderedCollection' -> 'OrderedCollection with: `@receiver'
when: [ `@receiver class IsKindOf: Collection ]
^ OrderedCollection with: self
We can probably do it with thisContext receiver or something like that.
recOrList below is a candidate
wipeImage: otherImage at: topLeft clippingBox: clipBox rectForIndex: rectForIndexBlock
| i clipRect t rectOrList waitTime |
i := 0.
clipRect := topLeft extent: otherImage extent.
clipBox ifNotNil: [clipRect := clipRect intersect: clipBox ifNone: [ ^ self ]].
[rectOrList := rectForIndexBlock value: (i := i + 1).
rectOrList == nil]
whileFalse: [
t := Time millisecondClockValue.
rectOrList asOrderedCollection do: [:r |
self copyBits: r from: otherImage at: topLeft + r topLeft
clippingBox: clipRect rule: Form over fillColor: nil].
waitTime := 3 - (Time millisecondClockValue - t).
waitTime > 0 ifTrue:
["(Delay forMilliseconds: waitTime) wait"]]
I do not get the following code
makeResolved
super makeResolved.
slots := self slots asOrderedCollection markAsRingResolved
Because self slots is defined as
slots
| allSlots |
allSlots := OrderedCollection new.
self slotsDo: [ :each | allSlots add: each].
^ allSlots asArray
@jordanmontt this is already related :)
I do not get the following code
makeResolved super makeResolved. slots := self slots asOrderedCollection markAsRingResolvedBecause self slots is defined as
slots | allSlots | allSlots := OrderedCollection new. self slotsDo: [ :each | allSlots add: each]. ^ allSlots asArray
fun
Hello,
We can indeed use deprecated: anExplanationString transformWith: aRule when: conditionBlock and write a rule that transforms only when the receiver isn't a collection. For example [ :ctx | (ctx receiver class = Collection) not ]. The problem is, as described in https://github.com/pharo-project/pharo/issues/14197, if we have polymorphism like in
objects := { Object new . OrderedCollection new }.
resultObjects := objects collect:[ :o | o asOrderedCollection ].
Even if we check with the rule that the receiver is not a collection, the first time it will check and as is not a collection, it will transform the code. The second time it will, and that is where the problem is…
asOrderedCollection is only deprecated on Object, for collections it still is there like asArray, asSet...
So what we do?
I don't think the issue is actionable in an evident way. The thing is to realize what are the callsites calling the deprecated methods, and rewrite those (and not the valid senders).
One way to do it is to run all the tests of Pharo. Tests triggering the deprecation will be rewritten. Then they can be committed.
The main issue is when there are polymorphic callsites: sometimes the receiver is a collection, sometimes it is not. In that case the rewriting will be correct only for one case. In that case, probably a case-by-case analysis is needed to see what to do.