[Swift] Protocol-conforming extension in different file from original definition causes linker error

Originator:AustinZheng
Number:rdar://20678789 Date Originated:23-Apr-2015
Status:Duplicate of 18448811 Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:Always
 
Summary:
If I have a type (e.g. a struct) with a property (let's call it "blah"), and then I declare a protocol that requires a property named "blah", and I then declare an empty extension to the struct in a different file that conforms to the protocol, I get linker errors when I try to build.

I've attached a very small project that demonstrates this.

Steps to Reproduce:
1. Create a new Swift project in Xcode
2. Declare a struct with a single property named "blah", which conforms to no protocols.
3. Create a protocol which declares a single property named "blah", requiring a getter.
4. Create another .swift file
5. In the new .swift file, declare an empty extension to the struct which conforms to the protocol.
6. Try to build.

NOTE: Either of the two steps below causes the build to succeed:
a. Move the extension into the file where the struct was originally defined
b. Remove the property requirement from the protocol

Expected Results:
Build succeeds. Alternately, build fails with a intelligible error message.

Actual Results:
Build fails with a message similar to the following:

Undefined symbols for architecture x86_64:
  "__TFV11ProtocolBug10SomeEntityg4blahSS", referenced from:
      __TTWV11ProtocolBug10SomeEntityS_15AnotherProtocolS_FS1_g4blahSS in test1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Version:
Xcode 6.3.1 (6D1002) running 6.3.1 command line tools; OS X 10.10.3

Notes:


Configuration:
Late 2013 15" Retina MBP

Comments

This Radar was recently closed as duplicate; I assume it was fixed as Victor said.

By AustinZheng at June 23, 2015, 6:11 p.m. (reply...)

this issue appears to be resolved in xCode 7(in initial public beta)

By victor.kolosov at June 11, 2015, 7:31 p.m. (reply...)

I have the same problem.

Undefined symbols for architecture armv7: "TFC3FRP6Signal9takeWhileUfGS0_Q__FT5queueGSqPS_11SerialQueue__4condFQSb_GS0_Q", referenced from: TFC11galleryTest14ViewController11viewDidLoadfS0_FT_T_ in ViewController.o

Troubleshooted it. Switched between framework and regular project type, no difference. Compared it to Alamofire, they seem to have extensions in different swift files and their stuff works. Current working theory is that extension has to be in a different swift file and also use generics.

Moving extension to the same file as the original object makes the compilation error to go away, but really! This is not a solution. Version: Xcode 6.3.2/6.4 beta; OSX 10.10.3

By victor.kolosov at June 4, 2015, 1:57 p.m. (reply...)

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!