Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
coffmark opened this issue Jan 21, 2025 · 1 comment
Closed

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

coffmark opened this issue Jan 21, 2025 · 1 comment
Labels
bug Something isn't working issue-handling Related to Issue handling within the testing library

Comments

@coffmark
Copy link

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
@coffmark coffmark added the bug Something isn't working label Jan 21, 2025
@grynspan
Copy link
Contributor

I know they don't look like the same issue, but the solution is the same: #840.

@grynspan grynspan added the issue-handling Related to Issue handling within the testing library label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working issue-handling Related to Issue handling within the testing library
Projects
None yet
Development

No branches or pull requests

2 participants