From ebddbbc3806bca27f880d1a5713aa55077b4c142 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 10 Apr 2023 19:26:20 -0400 Subject: [PATCH 1/3] CompiledMethod>>#removeProperty: remove the AdditionalMethodState on last removal --- src/Kernel/CompiledMethod.class.st | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Kernel/CompiledMethod.class.st b/src/Kernel/CompiledMethod.class.st index 03f04ebb761..03e2fe4f2e0 100644 --- a/src/Kernel/CompiledMethod.class.st +++ b/src/Kernel/CompiledMethod.class.st @@ -981,6 +981,9 @@ CompiledMethod >> removeProperty: propName [ (Association key: propName value: value)). + + "Remove unneded AdditionalMethodState" + self penultimateLiteral size = 0 ifTrue: [ self penultimateLiteral: self selector ]. ^value ] From 7f8cad2825d5bb9367d1c126c74eb591c14df281 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 10 Apr 2023 19:26:40 -0400 Subject: [PATCH 2/3] add CompiledMethodTest>>#testProperties --- .../CompiledMethodTest.class.st | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Kernel-Tests-Extended/CompiledMethodTest.class.st b/src/Kernel-Tests-Extended/CompiledMethodTest.class.st index 6613497a821..2d875006b1f 100644 --- a/src/Kernel-Tests-Extended/CompiledMethodTest.class.st +++ b/src/Kernel-Tests-Extended/CompiledMethodTest.class.st @@ -731,6 +731,53 @@ CompiledMethodTest >> testPragmaAt [ self assert: (method pragmaAt: #hello) equals: nil ] +{ #category : #test } +CompiledMethodTest >> testProperties [ + + | method tmp | + method := self class >> #returnTrue. + + "No property. Unlike classic collections, nil is returned on absence" + self deny: method hasProperties. + self deny: (method hasProperty: #doesNotExist). + self assert: (method propertyAt: #doesNotExist) equals: nil. + self assert: (method propertyAt: #doesNotExist ifAbsent: [ #tag ]) equals: #tag. + self assert: (method removeProperty: #doesNotExist) equals: nil. + self assert: (method removeProperty: #doesNotExist ifAbsent: [ #tag ]) equals: #tag. + + "Add a property" + self assert: (method propertyAt: #doesNotExist put: #yesItDoes) equals: #yesItDoes. + self assert: method hasProperties. + self assert: (method hasProperty: #doesNotExist). + self assert: (method propertyAt: #doesNotExist) equals: #yesItDoes. + self assert: (method propertyAt: #doesNotExist ifAbsent: [ #tag ]) equals: #yesItDoes. + + "Remove it" + self assert: (method removeProperty: #doesNotExist) equals: #yesItDoes. + self deny: method hasProperties. + self assert: (method removeProperty: #doesNotExist) equals: nil. + + "Add it back" + self assert: (method propertyAt: #doesNotExist ifAbsentPut: [ #yesItDoesAgain ]) equals: #yesItDoesAgain. + self assert: method hasProperties. + self assert: (method propertyAt: #doesNotExist) equals: #yesItDoesAgain. + + "Add a second one" + self assert: (method propertyAt: #doesExist put: #yesItDoes) equals: #yesItDoes. + + tmp := OrderedCollection new. + method propertyKeysAndValuesDo: [ :key :value | tmp add: { key . value } ]. + self assertCollection: tmp hasSameElements: #( #( #doesNotExist #yesItDoesAgain ) #(#doesExist #yesItDoes) ). + + "Remove both" + method removeProperty: #doesNotExist. + self assert: method hasProperties. + self assert: (method propertyAt: #doesNotExist) equals: nil. + self assert: (method propertyAt: #doesExist) equals: #yesItDoes. + method removeProperty: #doesExist. + self deny: method hasProperties +] + { #category : #'tests - instance variable' } CompiledMethodTest >> testReadsField [ | method | From 6ecdba9c104f3a20e1e9b887712ef85f66147139 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 10 Apr 2023 20:48:04 -0400 Subject: [PATCH 3/3] tests with s --- src/Kernel-Tests-Extended/CompiledMethodTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel-Tests-Extended/CompiledMethodTest.class.st b/src/Kernel-Tests-Extended/CompiledMethodTest.class.st index 2d875006b1f..2ce235bebaa 100644 --- a/src/Kernel-Tests-Extended/CompiledMethodTest.class.st +++ b/src/Kernel-Tests-Extended/CompiledMethodTest.class.st @@ -731,7 +731,7 @@ CompiledMethodTest >> testPragmaAt [ self assert: (method pragmaAt: #hello) equals: nil ] -{ #category : #test } +{ #category : #tests } CompiledMethodTest >> testProperties [ | method tmp |