Xcode 10.2 playgrounds: "expression failed to parse, unknown error"

In Xcode 10.1 I had a productive, working development setup. I had a single workspace containing a framework with three targets (macOS, iOS, tvOS), 5 app projects with three targets each (likewise, all using the framework), and a group containing 9 macOS playgrounds that successfully imported the framework and allowed easy unit testing/experimentation with the framework. The framework targets all had same Product Name so I didn't have to use #if os(...) at the top of every file to import platform-specific module names.


When I upgraded to Xcode 10.2, none of the playgrounds worked at all. The "import MyFramework" statement at the top triggered an error: "Could not find module 'MyFramework' for architecture 'x86_64'; found arm64". However, yesterday's 10.2.1 release fixed that problem.


With Xcode 10.2.1, now most of these playgrounds just generate an error but give me no pointer to the offending code, just "expression failed to parse, unknown error" in Xcode's Console pane, and a little drop-down strip at the top of the source editor window stating "The playground could not continue running because the playground source did not compile successfully."


There is one playground that works. The major differentiator with this one is that the code is only exercising (and displaying in the live view) the SpriteKit-based part of my framework, where the others are exercising the SceneKit-based parts (including a SpriteKit-based overlay).


So, the one working playground suggests that the problem isn't accessing my framework, but maybe something in my framework's codepath that touches SceneKit has something to do with it. But the 5 apps using the framework with SceneKit are working fine.


I'm just hoping there's a log somewhere, or some environment variables I could try setting that might help me get a clue as to what is going wrong in the playgrounds.


I noticed in the Xcode 10.2.1 release notes the following known issue that might possibly be related:

In some cases, compilation may fail without emitting a specific error. (49303574)

  • Workaround: Disable batch mode by adding the
    SWIFT_ENABLE_BATCH_MODE
    custom build setting and setting it to
    NO
    . If you’re invoking
    swift
    directly, include
    -disable-batch-mode
    on the command line.


But I don't understand how to add a custom build setting to a playground.


Thanks in advance for any help.


-Andy

FYI, FWIW, I reverted to Xcode 10.1 and (after changing the framework's settings to compile for Swift 4.2 rather than the 10.1-unsupported Swift 5.0), all my playgrounds work again. I think I'll stay with Xcode 10.1 for now... 10.2 doesn't give me anything I need right now, just headaches.

I made some progress, but have no idea why.


With all the playgrounds working in Xcode 10.1, I took a lot of code out of all of the playgrounds that was doing the same thing (setting up the NSViewController subclass and views and scene (model) it manages) and put it in my framework (PlaygroundTestViewController --just 34 lines of Swift). This vastly simplified all my playgrounds, made them easier to read and understand, and removed all that redundant code. I tested them all and they worked great with 10.1.


I decided to see if Xcode 10.2.1 would be happier with this new arrangement. I deleted Xcode 10.1 from my Applications folder, and copied Xcode 10.2.1 from a folder where I'd stashed it. However, that copy failed with an odd message from Finder about something missing. I tried just moving it to the Applications folder and got no error. However, Xcode wouldn't launch. The icon would zoom out like it was launching but it wouldn't open, even after waiting 5 minutes. I restarted, same thing. Figuring it had somehow gotten corrupted, I deleted it and re-downloaded it from the App Store.


After switching my framework back to compiling for Swift 5, I tried my playgrounds. and all but one worked --that includes several SceneKit-based ones that hadn't worked before my refactoring. The only thing unique about this one that fails, with the same "expression failed to parse, unknown error" message, is that it has a second SCNView+SCNScene as a subview overlaying the main SCNView+SCNScene+SKView+SKScene (overlay).


The failing playground is just 80 lines of code, 75 of which are defining a subclass of the new PlaygroundTestViewController subclass in my framework, adding that second SCNView+SCNScene and some test cases. (The subclass uses some other objects from the framework, too.) The last 5 lines of code create the VC and assign it to the playground live view.


The last thing I tried is making a new file in one of the app projects with the PlaygroundTestViewController subclass from the failing playground. Then in the keyDown event handler of that app's lone VC, it makes the playground's VC and presents it as a sheet. Works beautifully. No compiler warnings or errors, no runtime errors.


So, I'm just stumped. I'll stick with 10.2.1 for now, since I can live without that one playground working. But here's hoping 10.2.2 fixes this issue or helps me understand what expression it can't parse.


TIA for any tips on anything else I can try. (@eskimo?)


-Andy

Accepted Answer

Well, I found the offending line of code that couldn't be parsed.


I went to a playground that worked fine and added in code from the one that didn't piece by piece until I got the same errors: "expression failed to parse, unknown error" in Xcode's Console pane, and a little drop-down strip at the top of the source editor window stating "The playground could not continue running because the playground source did not compile successfully."


This was the line that worked fine in Xcode 10.1 but triggered the failure in Xcode 10.2.1:

scene.currentGame.isHidden = true


Both scene and currentGame are defined as instance variables of my base classes that are subclasses of SCNScene and SCNNode, respectively:


In the class GameViewController (a subclass of NSViewController):

var scene : BaseScene!


In the class BaseScene (a subclass of SCNScene):

var currentGame : BaseGame! (a subclass of SCNNode)


Adding one question mark fixed the problem:

scene.currentGame?.isHidden = true


I'll go re-read the Swift docs on implicitly unwrapped optionals, and ARC and unowned references... I've probably done something sloppy. But it's strange that the same code works fine in my app with Xcode 10.2.1 and in Xcode 10.1 playgrounds with but fails with Xcode 10.2.1 playgrounds.


And I think it's a bug that Xcode couldn't point to the line that failed... possibly because of the known issue mentioned in the 10.2.1 release notes mentioned above.


-Andy

Xcode 10.2 playgrounds: "expression failed to parse, unknown error"
 
 
Q