I've been encountering an issue with the Swift REPL for a while now, and chalked it up to being some kind of issue with my local environment. That is, until I got a new computer and the issue was happening there too. This has been happening consistently with Swift 5.2.4/Xcode 11 and Swift 5.3/Xcode 12. Stranger still, it used to not happen with Swift 5.2.4 - but then just started seemingly out of nowhere.
The Swift REPL consistently complains when I try to import SwiftPM modules, saying that it can't lookup the symbols. This is strange, but the code has no problem running in tests — just the REPL.
Here's a quick example of how to maybe reproduce this. For me, it happens with any SwiftPM library, so the specific one doesn't matter.
$ mkdir Example
$ cd Example
$ swift package init --type library
Edit Sources/Example/Example.swift to look like so:
public struct Example {
var text = "Hello, world!"
public init() {}
}
Next, launch the REPL.
$ swift run --repl
...
1> #if canImport(Example)
2. print("Proceed")
3. #endif
Proceed
4> import Example
5> let example = Example()
example: Example.Example = {
text = {
_guts = {
_object = {
_countAndFlagsBits = <extracting data from value failed>
_object = <extracting data from value failed>
}
}
}
}
error: Couldn't lookup symbols:
Example.Example.init() -> Example.Example
Example.Example.init() -> Example.Example
It's really strange, isn't it?
If it's helpful I can include a log of what LLDB logs, but it's a lot. Let me know if anyone else is having this issue or what I can do to fix it! Thanks.