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

[SR-11758] Undefined symbol: static allcases.MyEnum.allCases.getter : [allcases.MyEnum] #4652

Closed
kirilltitov opened this issue Nov 10, 2019 · 3 comments
Labels

Comments

@kirilltitov
Copy link

Previous ID SR-11758
Radar rdar://problem/57094069
Original Reporter @kirilltitov
Type Bug
Status Resolved
Resolution Duplicate
Environment

Latest Swift for macOS:

~ swift --version
Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
Target: x86_64-apple-darwin19.0.0

Latest Swift for Linux (official image):

# swift --version
Swift version 5.1 (swift-5.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
Votes 2
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 2f66bc205962fcbaa42526614feb3beb

duplicates:

  • SR-1393 [SwiftPM] Enforce Swift module import dependencies

Issue Description:

Something isn't working when it comes to testing allCases with XCTest:

// main.swift
public enum MyEnum: String, CaseIterable {
    case one, two
}
// allcasesTests.swift
import XCTest
import allcases

final class allcasesTests: XCTestCase {
    func testExample() throws {
        let _ = MyEnum.allCases
        XCTAssertTrue(true)
    }

    static var allTests = [
        ("testExample", testExample),
    ]
}
// in Linux
root@68c7baf2f177:/srv# swift test
/srv/Tests/allcasesTests/allcasesTests.swift:6: error: undefined reference to '$s8allcases6MyEnumO8allCasesSayACGvgZ'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
// in macOS
Undefined symbols for architecture x86_64:
  "_$s5Monad6MyEnumO8allCasesSayACGvgZ", referenced from:
      _$s10MonadTestsAAC11testExampleyyKF in MonadTests.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

GitHub repo with sample failing package: https://github.com/kirilltitov/allcases

@beccadax
Copy link
Contributor

brent@broyalgordon> swift demangle s8allcases6MyEnumO8allCasesSayACGvgZ
$s8allcases6MyEnumO8allCasesSayACGvgZ ---> static allcases.MyEnum.allCases.getter : [allcases.MyEnum]

I reproduced this in the 11/1 master snapshot, but couldn't make much headway—the missing symbol is present in both -emit-ir and -emit-assembly and appears to have attributes that should keep it from being stripped as dead code.

@swift-ci create

@kirilltitov
Copy link
Author

I have updated the test repo with another bug (same cause apparently). It seems like in executable packages testing isn't functional at all 🙁

// in main.swift
public struct MyStruct: Hashable {
    public let myValue: String = "defaultValue"
    public init() {}
}
// in tests
let _ = MyStruct()
Undefined symbol: allcases.MyStruct.init() -> allcases.MyStruct

@ankitspd
Copy link
Member

You can't link executable targets in any other target. Please refer to the template package generated by `swift package init` for a package with library and `swift package init --type executable` for a package with executable target. SwiftPM should prevent you from even importing this target but we don't have that yet. This is tracked by SR-1393

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants