Undocumented aspect of result builder

TLDR: result builders' buildExpression supports @autoclosure:

@MainActor
@resultBuilder
struct BodyBuilder {
    
    static var shouldExecuteExpressions = false

    static func buildExpression<T>(_ expression: @autoclosure () -> T) {
        if Self.shouldExecuteExpressions {
            _ = expression()
        }
    }
    
    static func buildBlock(_: Void...) { }
    
}

This is handy for some code that I'm writing, but it isn't explicitly documented anywhere (though the fact that it works makes sense to me.)

Is it reliable to depend on this, and if so, is it worth documenting?

1 Like

The closest I can find of "documented" is in the Future Directions that references usage of a valid @autoclosure to justify other developments.

1 Like

Yeah I saw that too :thinking: The "future" part is why I was surprised it worked