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-138] Foundation objects are not bridged on Linux as they are on OS X. #4378

Closed
swift-ci opened this issue Dec 8, 2015 · 3 comments
Closed

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Dec 8, 2015

Previous ID SR-138
Radar None
Original Reporter babt (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

OS X 10.11.1, Ubuntu 15.10

Additional Detail from JIRA
Votes 6
Component/s Compiler, Foundation
Labels Bug
Assignee @millenomi
Priority Medium

md5: fd4610a64cf6030b8952ae7fa9bfb6ba

is duplicated by:

  • SR-309 Unable to coerce String -> NSString
  • SR-5160 NSMutableCharacterSet cannot be coerced to CharacterSet under Linux
  • SR-5404 Linux: Cannot cast NSData to Data

Issue Description:

Foundation in this build does include NSString but there's lots a caveats associated with it. It's not bridged to String as it is on OS X yet and I suspect (but haven't verified yet,) that most other Foundation objects that are bridged on OS X are not yet bridged on Linux. So casting as in the example below will fail:

3> let foo: NSString = "foo"
 foo: Foundation.NSString = \{
 Foundation.NSObject = \{}
 _cfinfo =

\{ info = 1920 pad = 0 }

_storage = "foo"
 }
 4> let bar = foo as String
 repl.swift:4:11: error: cannot convert value of type 'NSString' to type 'String' in coercion
 let bar = foo as String
 ^~~

While on OS X, it will do as expected:

3> let foo:NSString = "foo"
 foo: NSString = "foo"
 4> let bar = foo as String
 bar: String = "foo"

In order for the Linux version of Swift-repl to recognize Foundation, it needs to be invoked as follows:

%: swift -lFoundation <rest of the parameters>

This tells Swift that you're using Foundation and to link (-l) with the Foundation shared library. However, this is not needed on OS X.

Feel free to contact me if you have any questions,

@parkera
Copy link
Member

parkera commented Dec 15, 2015

Adding the lldb component as well, for the REPL issue.

The lack of bridging is a (very unfortunate) known issue.

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 15, 2015

Comment by Kate Stone (JIRA)

To avoid derailing the bridging issue I'm removing LLDB for Swift from this issue. I've filed <rdar://problem/23902940> internally to track the notion that the broader notion that the REPL should respect a more inclusive notion of a default Swift "SDK" on Linux. What that should look like is a distinct and interesting question that probably deserves discussion on Swift.org, and it's definitely not REPL-specific.

@spevans
Copy link
Collaborator

spevans commented Aug 28, 2018

Bridging is now fixed in 4.2

$ cat sr_138.swift 
import Foundation

let foo: NSString = "foo"
let bar = foo as String
print("bar:", bar)

$ ~/swift-4.2-CONVERGENCE-ubuntu16.04/usr/bin/swift sr_138.swift 
bar: foo 

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

No branches or pull requests

3 participants