Linker error on extension of class using generics where extension contains function that references generic type
| Originator: | ash.furrow | ||
| Number: | rdar://18106414 | Date Originated: | August 22, 2014 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6 Beta 6 |
| Classification: | Serious Bug | Reproducible: | Always |
(note: sample project is at http://cloud.ashfurrow.com/2I2V193C3l0z )
Summary:
Ran into this problem. I have created a class that uses a generic, and I have an extension to that class *in another file* (this is really important). In my extension, I have a function that takes an argument of the type T, the generic type of my class. Then in my unit tests, I import the module created by my main target and create an instance of my class. Trying to call my extension's method yields a linker error.
Steps to Reproduce:
1. New Xcode project ("Single View" template)
2. Create new Swift file "Test.swift" in the main target and give it the following contents:
import Foundation
public class A<T> {
var t: T?
public init () {
}
}
3.Create another new file in the main target called "Test+Extension.swift" and give it the following contents:
import Foundation
extension A {
public func doSomething (c: T) -> String {
return "hi"
}
}
4. In your unit testing target, add an import statement at the top with the name of your main target.
5. In a unit test, create an instance of A<Int> and then try and call doSomething(2)
6. Run unit tests
Expected Results:
doSomething(2) returns "hi"
Actual Results:
Following linker error:
Ld /Users/ash/Library/Developer/Xcode/DerivedData/BugTest-gpaacovdzzcczecuomisszsbnmon/Build/Products/Debug-iphonesimulator/BugTest.app/BugTest normal x86_64
cd /Users/ash/Desktop/BugTest
export IPHONEOS_DEPLOYMENT_TARGET=8.0
export PATH="/Applications/Xcode6-Beta6.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode6-Beta6.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode6-Beta6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode6-Beta6.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk -L/Users/ash/Library/Developer/Xcode/DerivedData/BugTest-gpaacovdzzcczecuomisszsbnmon/Build/Products/Debug-iphonesimulator -F/Users/ash/Library/Developer/Xcode/DerivedData/BugTest-gpaacovdzzcczecuomisszsbnmon/Build/Products/Debug-iphonesimulator -filelist /Users/ash/Library/Developer/Xcode/DerivedData/BugTest-gpaacovdzzcczecuomisszsbnmon/Build/Intermediates/BugTest.build/Debug-iphonesimulator/BugTest.build/Objects-normal/x86_64/BugTest.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -lswiftCore -L/Applications/Xcode6-Beta6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/ash/Library/Developer/Xcode/DerivedData/BugTest-gpaacovdzzcczecuomisszsbnmon/Build/Intermediates/BugTest.build/Debug-iphonesimulator/BugTest.build/Objects-normal/x86_64/BugTest.swiftmodule -mios-simulator-version-min=8.0 -Xlinker -dependency_info -Xlinker /Users/ash/Library/Developer/Xcode/DerivedData/BugTest-gpaacovdzzcczecuomisszsbnmon/Build/Intermediates/BugTest.build/Debug-iphonesimulator/BugTest.build/Objects-normal/x86_64/BugTest_dependency_info.dat -o /Users/ash/Library/Developer/Xcode/DerivedData/BugTest-gpaacovdzzcczecuomisszsbnmon/Build/Products/Debug-iphonesimulator/BugTest.app/BugTest
Undefined symbols for architecture x86_64:
"_swift_allocateGenericClassMetadata", referenced from:
_create_generic_metadata in Test.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!