REPL fails to import mixed frameworks with a C header

Originator:pyry.jahkola
Number:rdar://20135930 Date Originated:2015-03-12
Status:Closed Resolved:2015-06-08
Product:Developer Tools Product Version:Xcode 6.3 beta 2 (6D532l)
Classification:Other Bug Reproducible:Always
 
Summary:
Frameworks that contain Objective-C fail to import on the Swift REPL. That makes it hard to interactively work with own and 3rd-party libraries we use.

In particular:

- BUG: Cannot import into the REPL a mixed-source framework "Foo.framework" created with the standard Cocoa Framework template. The REPL (run as "swift -F path/to/framework") clearly finds the framework but fails and soon crashes when trying to "import Foo".

- EXPECTED: Can import the above framework into a Swift script (run as "swift -F path/to/framework Test.swift").

- EXPECTED: Can import and dynamically link the framework in a Swift file compiled with "swiftc -F path/to/framework Test.swift -o Test" and run with "DYLD_FRAMEWORK_PATH=path/to/framework ./Test".

- EXPECTED: Can import and dynamically link the framework in a compiled Swift project.

- SURPRISINGLY: Can import the same framework as soon as all C headers are removed from the target!

Steps to Reproduce:
Grab and build the attached files. In Terminal.app, "cd" to the project directory and run the commands:

```
# (1) Succeeds:
echo 'import Foo; foo()' | xcrun -sdk macosx swiftc -F Mixed - -o Test && DYLD_FRAMEWORK_PATH=Mixed ./Test

# (2) Fails:
echo 'import Foo; foo()' | swift -F Mixed

# (3) Fails likewise:
echo 'import Foo; foo()' | xcrun -sdk macosx swift -F Mixed

# (4) Succeeds, but contains no C headers:
echo 'import Foo; foo()' | swift -F Swift
```

TO RECREATE THE ATTACHMENT:

1. In Xcode (e.g. 6.3 beta 2), create a new project.
2. Choose "Cocoa Framework" under OS X / Framework & Library.
3. Language option Swift. (But happens with Objective-C as well.)
4. Add a Swift file to the project, and a public function.
5. Check that Defines Module is set in Build Settings.
6. Build.

TO RECREATE THE SWIFT-ONLY FRAMEWORK:

1. Uncheck "Target Membership" for the file "Foo.h".
2. Build.

Expected Results:
Expected the import to work when the C header was present.

Actual Results:
(1) prints:

```
It works!
```

(2) and (3) fail with the error:

```
Welcome to Swift version 1.2. Type :help for assistance.
repl.swift:1:8: error: cannot load underlying module for 'Foo'
import Foo; foo()
       ^
A fatal parse error has occurred.  LLDB may become unstable; please restart your debug session as soon as possible.
```

(4) prints:

```
Welcome to Swift version 1.2. Type :help for assistance.
It works!
```

Version:
Happens in both:
- Xcode 6.2 (6C131e)
- Xcode 6.3 beta 2 (6D532l)

Notes:
I asked about this bug in the Developer Forums, https://devforums.apple.com/message/1108998#1108998

Configuration:
Happens in all OS X & Xcode configurations I've tested.

Attachments:
'Foo.zip' was successfully uploaded.

Comments

Seems to be fixed in Xcode 6.3.2

I can no longer reproduce this issue in Swift 1.2 and Xcode 6.3.2. Which means that mixed-source frameworks now work!

One gotcha I found though: In your framework, use the #import "Foo.h" syntax rather than #import <Foo/Foo.h>.

By pyry.jahkola at June 8, 2015, 11:39 a.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!