Skip to content

[Cannot Compile] with parameter pack and number of elements is 1 #923

Closed as duplicate of#162
@coffmark

Description

@coffmark

Description

If I implement a function that uses parameter packs in swift-testing, and it fails to compile if there is only one element.

If I don't use swift-testing, it will compile successfully.

The example code is shown below.

struct ParameterPackTests {
  func lessThan<each Element: Comparable>(lhs: (repeat each Element), rhs: (repeat each Element)) -> Bool {
      var hasElement = false

      for (leftHandSide, rightHandSide) in repeat (each lhs, each rhs) {
          hasElement = true
          guard leftHandSide < rightHandSide else { return false }
      }
      return hasElement
  }
  
  @Test("")
  func test() {
    print(lessThan(lhs: 0, rhs: 1)) // true
    #expect(lessThan(lhs: (0, 1), rhs: (1, 2)) // Success

    // 🟥 ERROR: No exact matches in call to global function '__checkFunctionCall'
    // 🟥 ERROR: Generic parameter 'each Element' could not be inferred
    #expect(lessThan(lhs: 0, rhs: 1))
    //    Testing.__checkFunctionCall((),calling: {
    //      lessThan(lhs: $1,rhs: $2)
    //    },0,1,expression: .__fromFunctionCall(nil,"lessThan",("lhs",.__fromSyntaxNode("0")),("rhs",.__fromSyntaxNode("1"))),comments: [],isRequired: false,sourceLocation: Testing.SourceLocation.__here()).__expected()
  }
}

Expected behavior

If I implement a function that uses parameter packs in swift-testing, it will compile successfully even if there is only one element.

Actual behavior

If I implement a function that uses parameter packs in swift-testing, and it fails to compile if there is only one element.

Steps to reproduce

  1. Run the test for the example code.
  2. Compilation fails.

swift-testing version/commit hash

main (1747fb0c795ca490463aad8c3b2d8815f7c3222f)

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

$ swift --version
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

$ uname -a
Darwin M1-Mac-Book-Pro.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000 arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🪲 Something isn't workingissue-handlingRelated to Issue handling within the testing library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions