CustomStringConvertible and rethrows in Playgrounds

Can you correctly run the below code in Playgrounds?

struct BuggyStruct {
    func bug(_ body: (Int) throws -> Void) rethrows { try body(0) }
}
extension BuggyStruct : CustomStringConvertible {
    var description: String {
        var text = "Bug"
        self.bug({ element in
            text += "\(element)"
        })
        return text
    }
}
do {
    print(BuggyStruct())
}

I got error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=2, address=0x7ffeeeb54ff8). The computed variable description was used many times (more than 1000 times as shown in the side bar of Playgrounds). When using throws instead of rethrows and adding try! at the throwing function self.bug({...}), I got no error.

I already filed this crash for Apple's Bug Reporter, but I have no response from Apple.

I see the crash too, in a playground, but not when I compile and run it as a file by itself.

A great place to file Swift bugs is bugs.swift.org, which gives external developers like yourself more insight into the process, is a more efficient way to request updates on progress, ask questions and get answers, and, also means the bugs get directly to us, instead of having to be filtered through the huge Bug Reporter system to finally reach the Swift team. If you file this same bug there, and let us know the radar number, we can link them together.

My bug report has the number: 41460357.

I filed this same bug for bugs.swift.org.

1 Like