pharo-project / pharo

Pharo is a dynamic reflective pure object-oriented language supporting live programming inspired by Smalltalk.
http://pharo.org
Other
1.19k stars 352 forks source link

Error filing in an existing method that has been moved to another non-base package causes walkback #11049

Open StewMacLean opened 2 years ago

StewMacLean commented 2 years ago

Bug description When an existing method is moved to another non base package, then filed out, it causes an error on fileIn to a fresh image as the non base package doesn't exist.

To Reproduce Steps to reproduce the behavior:

  1. Create a new package, say "X".
  2. Move an existing method to the new package, creating an extension.
  3. FileOut the package and file it into a fresh image
  4. A walkback occurs as "name is sent to nil" (which should be the newPackage)

Expected behavior The package should fileIn without any errors. i.e. create the new package and put the extension in it

Screenshots N/A

Version information:

Expected development cost Nil - please see fix below:

ClassDescription>>notifyRepackage: selector method: compiledMethod oldProtocol: oldProtocol newProtocol: newProtocol

"Stewart MacLean 24/03/22 - fix so that a newPackage is created, if it doesn't exist.
This can happen when filing in an existing method that has been moved to a new non-base package."

| oldPackage newPackage organizer |

(newProtocol = oldProtocol)
    ifTrue: [ ^ self ].

"This indirection is because we need to abstract RPackage from the kernel"
self class environment at: #RPackage ifPresent: [ :rPackageClass | 
        "Original code: - answers nil if package doesn't exist. This causes problems later on in recategorisation, as expects a Package.
        =====================================
        newPackage := rPackageClass organizer 
            packageForProtocol: newProtocol 
            inClass: self.
        ======================================="
        "Fix code: if a package for the Class/Protocol exists answer it, otherwise create one."
        "======================================="
        organizer := rPackageClass organizer.
        newPackage := (organizer hasPackageForProtocol: newProtocol inClass: self)
            ifTrue: [organizer packageForProtocol: newProtocol inClass: self]
            ifFalse: [organizer registerPackage: (organizer packageClass named: (newProtocol copyWithout: $*))].
        "========================================"
        oldPackage := rPackageClass organizer 
            packageForProtocol: oldProtocol 
            inClass: self.

        "Announce recategorization"
        newPackage = oldPackage
            ifFalse: [ 
                SystemAnnouncer uniqueInstance 
                    methodRepackaged: compiledMethod 
                    from: oldPackage 
                    to: newPackage ] ]. 

SystemAnnouncer uniqueInstance methodRecategorized: compiledMethod oldProtocol: oldProtocol
welcome[bot] commented 2 years ago

Thanks for opening your first issue! Please check the CONTRIBUTING documents for some tips about which information should be provided. You can find information of how to do a Pull Request here: https://github.com/pharo-project/pharo/wiki/Contribute-a-fix-to-Pharo

GitHub
Contribute a fix to Pharo · pharo-project/pharo Wiki
Pharo is a dynamic reflective pure object-oriented language supporting live programming inspired by Smalltalk. - Contribute a fix to Pharo · pharo-project/pharo Wiki
jordanmontt commented 2 years ago

Hello @StewMacLean We just tested it on Pharo 10 and it works without problem. Can you test your problem on Pharo 10?

Because Pharo 10 is about to be released so we only do show-stoppers on Pharo 9.