Strange linker error while running tests

Hi,

I am facing a strange linker error. Need some inputs on the same. You can find the sample code here.

Code is pretty simple and straightforward.

public struct myNumber<T: Numeric> {
    var num:T = .zero
}

let v = myNumber(num:5)
print(v.num)

This runs and compiles fine swift run swiftNumber will print 5 on the console. No worries here.

How ever problem begins when I try to write a test for the same.

import XCTest
import class Foundation.Bundle

@testable import swiftNumber

final class swiftNumberTests: XCTestCase {
  func testNum() {
    let v = myNumber(num:1)
    XCTAssertEqual(1, v.num)
  }
}

when i run the command swift test --enable-test-discovery I get the following error.

swiftNumberTests.swift:8: error: undefined reference to '$s11swiftNumber02myB0V3numACyxGx_tcfC'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

It is not able to find the reference for myNumber which is present in main.swift file. Not sure what is going wrong.
Here is the check job which is failing in github actions.

Any inputs will be helpful.

If any one interested in knowing the build and run output with -v option. Here is the log

$ xcrun swift-demangle s11swiftNumber02myB0V3numACyxGx_tcfC
$s11swiftNumber02myB0V3numACyxGx_tcfC ---> swiftNumber.myNumber.init(num: A) -> swiftNumber.myNumber<A>

That looks as if it should work since the default initializer should be internal and you are using a @testable import. Do you see different results when adding a public initializer?

Nope. Adding public init doesn't change it's behavior.
Same error here is the log.

Is this a bug? should i file one?

Seems like a bug to me, would be great if you could file it. Thanks!

@NeoNacho Thanks for the respones. Can you pleas let me know where should I file this bug? Is it a LLDB/Clang bug or the Swift bug?

Created a bug. https://bugs.swift.org/browse/TF-1340 Please let me know if this needs any correction.

Did you mean to file a bug against Swift for TensorFlow?

Hi @xwu , I tested it in Swift5.2, Swift5.3 and S4TF I found the same behaviour in all of the Swift versions.

In that case, you should file a bug against Swift instead of Swift for TensorFlow specifically.

Okay got it. I didn't realize I raised it under TF board. Have a new bug created under Swift.https://bugs.swift.org/browse/SR-13651

Terms of Service

Privacy Policy

Cookie Policy