Found a bug in SBCL 1.5.4

While implementing a version of change-class specializing on a metaclass as mentioned in the previous post, I noted that the resultant instance (unless change-class got called with initargs) had all slot values as nil or unbound. This puzzled me, since the spec stated that change-class preserves values for slots present in both the from-class and to-class (with presence determined by the slot names).

To make sure I hadn’t misread the spec, I tried some sample calls to change-class for some standard objects without a custom metaclass. And those did indeed preserve the slots in common between the from-class and to-class. Puzzling.

So, I implemented a method on update-instance-for-different-class, which change-class delegates part of the work to. The arguments to update-instance-for-different-class looked fine. Manually setting the common slot values worked fine. What was going on?

To take a look under the hood, I downloaded the SBCL source code from github and found the implementation for change-class and started looking at it piece-by-piece in the REPL. The extracted class representations looked fine, the sets of slots looked fine… And then the source code used a function not present in the SB-PCL package in my REPL. Now, that’s promising – probably recently changed, then?

And indeed – I went to the SBCL page and found that the newest version of SBCL is 2.0.4. And there’d been a fix related to change-class in version 2.0.2. Well, I updated my SBCL from 1.5.4 to 2.0.4, tried the sample calls to change-class for my metaclass, and… they worked fine!

In summary, then: 1) I had indeed identified a bug/defect in the implementation. 2) It had been fixed already, so no need to wait around for a fix (or try my own hand on an unknown codebase). 3) No need for my custom method on update-instance-for-different-class, so I got to delete that one and save some lines, all for the cheap cost of updating my SBCL version. Coolio! There’s admittedly something fun about managing to identify a bug/defect.

Click Here to Leave a Comment Below