@autoclosure causes Segmentation Fault

Experimenting with @autoclosure with variatic parameters. With that qualifier there, compiler faults. Comment just "@autoclosure" out, then it compiles just fine. Code:


fileprivate func LOG(_ flag: Int, _ items: @autoclosure Any..., separator: String = " ", terminator: String = "\n") {
    if flag > 0 {
        // Commenting these out has no effect
        let str = items.map{String(describing: $0)}.joined(separator: separator)
        print(str, terminator: terminator)
    }
}

class ViewController: UIViewController {
    var notificationTimer = DispatchWorkItem(block: {} )

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        LOG(1, "Does it get called?", 5, 7, expensiveFunc())        // Segmentation fault
        //LOG(0, "Does it get called?", expensiveFunc())            // OK
    }

    func expensiveFunc() -> String {
        print("CALLED")
        return "EXPENSIVE!!!"
    }
}

Fault:

<unknown>:0: error: unable to execute command: Segmentation fault: 11

<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)


Xcode 11.2, Mac -> latest Catalina, Target iPhone 13.2


Where should I enter the bug report? Also, is there a workaround for this?

Accepted Reply

Entered a bug on Swift.org, it was accepted, and as a result two other bugs were found :-)


https://bugs.swift.org/browse/SR-11934

Replies

Experimenting with

@autoclosure
with variadic parameters.

Well, that’s courageous (-:

Where should I enter the bug report?

Compiler crashes are always bugworthy. For Swift compiler crashes, I recommend filing a Swift bug; it’s easier to view it’s status that way.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Entered a bug on Swift.org, it was accepted, and as a result two other bugs were found :-)


https://bugs.swift.org/browse/SR-11934