Skip to content

Build fails when passing @autoclosure () -> Comment? = nil to #expect  #485

@HannesSteiner

Description

@HannesSteiner

Description

The build fails when passing @autoclosure () -> Comment? to the #expect macro. Although the macro allows to pass it: https://github.com/apple/swift-testing/blob/3f73ced40e763ec193a4180726578ab430218abe/Sources/Testing/Expectations/Expectation%2BMacro.swift#L25

(Other macros are affected as well.)

Expected behavior

This builds successfully:

func testFunctionWithComment(
    _ comment: @autoclosure () -> Comment?
) {
    #expect(true, comment())
}

Actual behavior

Building this returns an error:

Cannot convert value of type 'Comment?' to expected element type 'Array<Comment>.ArrayLiteralElement' (aka 'Comment')

Because the expanded version:

Testing.__checkValue(true, expression: .__fromSyntaxNode("true"), comments: [comment()], isRequired: false, sourceLocation: Testing.SourceLocation()).__expected()

Does not allow a optional Comment.

Steps to reproduce

Just try to build this:

import Testing

func testFunctionWithComment(
    _ comment: @autoclosure () -> Comment? = nil
) {
    #expect(true, comment())
}

swift-testing version/commit hash

3f73ced

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0
Darwin hannes-macbook-pro.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🪲 Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions