scripts/image-fixes/20-Ring2ChunkImporterTest.stBehaviorOwnedChunk (new instance variable isMetaclassTrait, added with addInstVarNamed:), BehaviorOwnedChunk>>isMetaclassTrait, BehaviorOwnedChunk>>isMetaclassTrait:, ChunkFileFormatParserV100>>parseMethodDeclarations:, RGChunkImporter>>visitMethodChunk:, Ring2ChunkImporterTest>>testStandardMethodInNewMetaclassTrait, Ring2ChunkImporterTest>>testMultipleMixedChunksInStrangeOrderWithMetaclassTraitBoth tests were expected failures because the chunk parser (ChunkFileFormatParserV100>>parseMethodDeclarations:) turned '!Foo classTrait methodsFor:' into only isMeta=true, so RGChunkImporter>>visitMethodChunk: could not tell a classTrait from a class-side method and created an RGClass where a trait was meant (test 1 then died in convertToMetaclassTrait with 'This class cannot be converted to trait'; test 2 got a class instead of a trait). The fix adds an instance variable isMetaclassTrait (with accessors) to BehaviorOwnedChunk, sets it in the parser, and makes the importer use environment ensureMetaclassTraitNamed: for such chunks. Real code import is unaffected (isMeta and behaviorName are unchanged). Test 2 also had three obsolete expectations that I changed: it read the method from 'trait metaclass' (the Ring trait metaclass is a separate unresolved object; the class side of a trait is classTrait, as the test's own next assertion and testStandardMethodInExistingMetaclassTrait use), it used the old-format stamp '5/2/2012 13:35' that RGStampParser cannot read (DateAndTime asDateAndTime raises DateError on both VMs; RGStampParser>>timeForStamp: falls back to epoch; the sibling tests use ISO stamps), and it checked 'protocol' as a resolved property and 'protocol name' although RGMethod>>protocol returns a Symbol stored in tags (siblings use #tags and 'protocol equals:'). Test 1 had a copy-paste assertion (trait isMetaclassTrait not on the 'TEmpty classTrait' behavior) which is changed to isMetaclassTrait, plus a check that TEmpty itself is a trait. Both tests had the expectedFailure pragma and its comment removed.
| Test | Defect in | State | Cause |
|---|---|---|---|
Ring2ChunkImporterTest>>testMultipleMixedChunksInStrangeOrderWithMetaclassTrait |
image-code | repaired | Chunk parser drops the 'classTrait' marker; importer creates a class for 'TEmpty classTrait methodsFor:' and later fails converting it. Test also asserted isMetaclassTrait not on a classTrait (copy-paste from the non-classTrait sibling test). |
Ring2ChunkImporterTest>>testStandardMethodInNewMetaclassTrait |
both-vms | repaired | Same importer defect (classTrait marker lost), plus obsolete test expectations: trait metaclass instead of classTrait, old-format stamp unreadable by RGStampParser, protocol/protocol name instead of tags/protocol Symbol. The 'defectIn' value both-vms is not right: the defect is in image code and the test, identical on both VMs; no VM difference was found. |
Regression check: Fix applied with mkimage.sh (image dir <work directory>), whole classes run on both VMs, base image vs fixed image. Ring2ChunkImporterTest: ours 32 pass/1 fail/1 error before, 34 pass after; Cog same (32/1/1 before, 34 after). ChunkFileFormatParserV100Test 6/6 both VMs before and after. CodeImportTest 12/12, CodeImporterCodeSnippetTest 1/1, MCFileInTest 1/1, RGEnvironmentTest 18/18, all on both VMs, before and after. Our VM run with the default JIT setting ('ours'); I did not run ours-nojit. The fix file was only ever applied on top of the base images; I did not test applying it twice (the entries are guarded by instVar/includes/source checks and print SKIP when the defect is absent, but the second apply was not run). Not run: Ring-Core-Tests beyond RGEnvironmentTest, Monticello tests other than MCFileInTest.
Upstream note: Pharo (CodeImport + Ring-ChunkImporter): Ring chunk importer creates a class for 'Foo classTrait methodsFor:' chunks. Title: "RGChunkImporter: import classTrait method chunks into the metaclass trait". The V100 chunk parser keeps only isMeta for '!TFoo classTrait methodsFor:'. Add BehaviorOwnedChunk>>isMetaclassTrait (set by ChunkFileFormatParserV100>>parseMethodDeclarations:), and let RGChunkImporter>>visitMethodChunk: use RGEnvironment>>ensureMetaclassTraitNamed: for such chunks. This lets the two Ring2ChunkImporterTest tests, which were marked expectedFailure, pass; their obsolete expectations (trait metaclass vs classTrait, d/m/y stamp, protocol as resolved property) were updated to match the sibling tests. Upstream: pharo-project/pharo. This is only a draft; the owner must review it before anything goes to Pharo or Cog.
Last full sweeps of 2026-11-17: iospharo (sweep14-new14) and stock Cog with the Cog changes (sweepcogp14-new10), with all image fixes. "Before" is the state of the test before the repairs. The Stock Cog column has a value only where the record measured stock Cog: "PASS 3 of 3 (repair run)" is the check of each repair on stock Cog v12.0.6 with the fix entry; "-" is not measured separately.
| Test | Before | State | iospharo VM | Patched Cog | Stock Cog |
|---|---|---|---|---|---|
Ring2ChunkImporterTest>>testMultipleMixedChunksInStrangeOrderWithMetaclassTrait | XFAIL | repaired | PASS | PASS | PASS 3 of 3 (repair run) |
Ring2ChunkImporterTest>>testStandardMethodInNewMetaclassTrait | XFAIL | repaired | PASS | PASS | PASS 3 of 3 (repair run) |
Run the tests in a Pharo 14 image (build 791). Before the fix they skip, fail or carry the expected-failure mark.
"Run in a Playground of a Pharo 14 image (Do it and print each line)." ((Ring2ChunkImporterTest selector: #testMultipleMixedChunksInStrangeOrderWithMetaclassTrait) run) printString. ((Ring2ChunkImporterTest selector: #testStandardMethodInNewMetaclassTrait) run) printString.
testMultipleMixedChunksInStrangeOrderWithMetaclassTrait
| importer trait method |
<expectedFailure>
"This test currently needs to fail because the CodeImporter gives only original behavior name and #isMata.
We do not know that the behavior was supposed to be classTrait."
importer := RGChunkImporter new.
importer fileInFrom: '!TEmpty classTrait methodsFor: ''some protocol'' stamp: ''GuillermoPolito 5/2/2012 13:35''!
someMethod
^true! !
Trait named: #TEmpty
uses: {}
package: ''Traits-Kernel-Traits''!' readStream.
trait := importer environment ask behaviorNamed: #'TEmpty classTrait'.
self assert: trait isNotNil.
self assert: (trait isTrait and: [ trait isMetaclassTrait not ]).
method := trait methodNamed: #someMethod.
self assert: method isNotNil.
self assert: (method sourceCode endsWith: '^true')testStandardMethodInNewMetaclassTrait
| importer trait method code |
<expectedFailure>
"This test currently needs to fail because the CodeImporter gives only original behavior name and #isMata.
We do not know that the behavior was supposed to be classTrait."
importer := RGChunkImporter new.
code := '!SomeTrait classTrait methodsFor: ''some protocol'' stamp: ''GuillermoPolito 5/2/2012 13:35''!someMethod
^true'.
importer fileInFrom: code readStream.
trait := importer environment ask behaviorNamed: #SomeTrait.
method := trait metaclass methodNamed: #someMethod.
self assert: trait isTrait.
self assert: trait classTrait isMetaclassTrait.
self assert: method isNotNil.
self assert: method isRingResolved.
self assert: (method hasResolvedAll: #(name protocol sourceCode author time)).
self assert: method name equals: #someMethod.
self assert: method protocol name equals: 'some protocol'.
self assert: method author equals: 'GuillermoPolito'.
self assert: method time equals: ('5/2/2012 13:35' asDateAndTime).
self assert: method sourceCode equals: 'someMethod
^true'How to apply an entries file: file in 00-header.st and the entries file as one chunk (the iospharo script scripts/gen-image-fixes.py makes that chunk). Each entry checks for the defect first and prints FIXED, ADDED or SKIP. Download 00-header.st.
"The chunk parser reads '!Foo classTrait methodsFor: ...' but stores only isMeta,
so the importer cannot tell a class-side method from a classTrait method and
creates a class where a trait is meant. Keep the distinction in the chunk."
(BehaviorOwnedChunk instVarNames includes: #isMetaclassTrait)
ifFalse: [
BehaviorOwnedChunk addInstVarNamed: 'isMetaclassTrait'.
Stdio stdout nextPutAll: 'ADDED BehaviorOwnedChunk instVar isMetaclassTrait'; lf; flush ]
ifTrue: [ Stdio stdout nextPutAll: 'SKIP BehaviorOwnedChunk instVar (already present)'; lf; flush ].
add value: #BehaviorOwnedChunk value: #isMetaclassTrait value: 'accessing'
value: 'isMetaclassTrait
"True when the chunk was declared as ''Foo classTrait methodsFor: ...'' (the class side of a trait)."
^ isMetaclassTrait ifNil: [ false ]'.
add value: #BehaviorOwnedChunk value: #isMetaclassTrait: value: 'accessing'
value: 'isMetaclassTrait: aBoolean
isMetaclassTrait := aBoolean'.
fix value: #ChunkFileFormatParserV100 value: #parseMethodDeclarations:
value: [ :s | (s includesSubstring: 'isMetaclassTrait') not ]
value: 'parseMethodDeclarations: methodsPreamble
| behaviorName isMeta isMetaclassTrait protocol stamp methodSource methodMetadata |
"The method preable is an array with the following structure:
If instance side method:
#(#CodeImportTestCaseTestClass #methodsFor: ''some protocol'' #stamp: ''GuillermoPolito 5/2/2012 13:35'')
if class side:
#(#CodeImportTestCaseTestClass #class #methodsFor: ''some protocol'' #stamp: ''GuillermoPolito 5/2/2012 13:35'')
if class side of a trait:
#(#TSomeTrait #classTrait #methodsFor: ''some protocol'' #stamp: ''GuillermoPolito 5/2/2012 13:35'')
Sometimes there is no timestamp:
#(#CodeImportTestCaseTestClass #methodsFor: ''some protocol'')
"
behaviorName := methodsPreamble first.
isMetaclassTrait := methodsPreamble second = #classTrait.
isMeta := methodsPreamble second = #class or: [ isMetaclassTrait ].
protocol := isMeta
ifTrue: [ methodsPreamble at: 4 ]
ifFalse: [ methodsPreamble at: 3 ].
stamp := ''''.
methodsPreamble size > 4 ifTrue: [
stamp := isMeta
ifTrue: [ methodsPreamble at: 6 ]
ifFalse: [ methodsPreamble at: 5 ] ].
methodSource := readStream next.
methodMetadata := readStream next.
self addDeclaration: ((self methodChunkClass
contents: methodSource
behaviorName: behaviorName asSymbol
isMeta: isMeta
protocol: protocol
stamp: stamp)
isMetaclassTrait: isMetaclassTrait;
metadata: methodMetadata;
yourself)'.
fix value: #RGChunkImporter value: #visitMethodChunk:
value: [ :s | (s includesSubstring: 'isMetaclassTrait') not ]
value: 'visitMethodChunk: aChunk
| theClass theMethod theProtocol |
theClass := aChunk isMetaclassTrait
ifTrue: [ self environment ensureMetaclassTraitNamed: (aChunk behaviorName , '' classTrait'') asSymbol ]
ifFalse: [ self classNamed: aChunk behaviorName ].
(aChunk isMeta and: [ aChunk isMetaclassTrait not ]) ifTrue: [ theClass := theClass classSide makeResolved ].
theMethod := theClass ensureLocalMethodNamed: aChunk methodSelector asSymbol.
theProtocol := theClass ensureProtocolNamed: aChunk protocol asSymbol.
theMethod protocol: theProtocol.
theMethod sourceCode: aChunk contents.
theMethod author: (RGStampParser authorForStamp: aChunk stamp).
theMethod time: (RGStampParser timeForStamp: aChunk stamp)'.
fix value: #Ring2ChunkImporterTest value: #testStandardMethodInNewMetaclassTrait
value: [ :s | s includesSubstring: '<expectedFailure>' ]
value: 'testStandardMethodInNewMetaclassTrait
| importer trait method code |
importer := RGChunkImporter new.
code := ''!SomeTrait classTrait methodsFor: ''''some protocol'''' stamp: ''''GuillermoPolito 2012-05-02T13:35''''!someMethod
^true''.
importer fileInFrom: code readStream.
trait := importer environment ask behaviorNamed: #SomeTrait.
method := trait classTrait methodNamed: #someMethod.
self assert: trait isTrait.
self assert: trait classTrait isMetaclassTrait.
self assert: method isNotNil.
self assert: method isRingResolved.
self assert: (method hasResolvedAll: #(name tags sourceCode author time)).
self assert: method name equals: #someMethod.
self assert: method protocol equals: ''some protocol''.
self assert: method author equals: ''GuillermoPolito''.
self assert: method time equals: (DateAndTime fromString: ''2012-05-02T13:35'').
self assert: method sourceCode equals: ''someMethod
^true'''.
fix value: #Ring2ChunkImporterTest value: #testMultipleMixedChunksInStrangeOrderWithMetaclassTrait
value: [ :s | s includesSubstring: '<expectedFailure>' ]
value: 'testMultipleMixedChunksInStrangeOrderWithMetaclassTrait
| importer trait method |
importer := RGChunkImporter new.
importer fileInFrom: ''!TEmpty classTrait methodsFor: ''''some protocol'''' stamp: ''''GuillermoPolito 5/2/2012 13:35''''!
someMethod
^true! !
Trait named: #TEmpty
uses: {}
package: ''''Traits-Kernel-Traits''''!'' readStream.
trait := importer environment ask behaviorNamed: #''TEmpty classTrait''.
self assert: trait isNotNil.
self assert: trait isMetaclassTrait.
self assert: (importer environment ask behaviorNamed: #TEmpty) isTrait.
method := trait methodNamed: #someMethod.
self assert: method isNotNil.
self assert: (method sourceCode endsWith: ''^true'')'.
State of 2026-11-20. Made from the test records of the iospharo project (a second Pharo VM). The fixes are proposals for review.