Recursive enum 'Optional<Wrapped>' is not marked 'indirect'

I'm getting this error in my project: Recursive enum 'Optional<Wrapped>' is not marked 'indirect'

But the project contains only one enum, and it isn't recursive. This is all there is to it:


enum SymbolType { case ATM, UOP, BOP, LP, RP, NaS }


The debugger provides no line number for the error. Can anyone advise me about how to track this down? It seemed to come out of nowhere.


dkj

Answered by DTS Engineer in 118264022

The issue you have here is that

Formula
is a recursive struct (via the
subformulas
property), which Swift doesn’t allow. The error message is completely bogus, but if you comment out enough code you’ll eventually get the right error.
/Users/quinn/Desktop/xxy/xxy/Formula.swift:11:8: error: recursive value type 'Formula' is not allowed
struct Formula {

It’s clear that Swift’s diagnostics have failed you completely here; please file a bug about that, then post your bug number, just for the record.

As to what you should do, you have the usual options when dealing with recursive data structures:

  • use a reference type

  • use an indirect enum

If someone can tell me what's causing this error, I'll name my first-born child after them.

Nah, there’s already too many Quinns in this world (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I gave up looking for the bug, deleted the project, and restarted Xcode. I created a new project, and before I could write a single line of code, this same error occurred again. So I guess all development comes to a halt.


Sometimes I wish I'd stayed with Windows.


PS: And now I find this error occurs only if I give the new project the same name as the one I deleted. Curiouser and curiouser. But at least I can keep working.

Xcode stores information about your project in

~/Library/Developer/Xcode/DerivedData/ppp-hhh
, where
ppp
is the project name and
hhh
is a hash of the path to the project (technically this is the workspace, not the project, but if you’re not using workspaces your projects have an embedded workspace so it ends up being the same thing). If you create a project with the same name in the same directory, these values end up being the same, so you inherit the derived data directory from your previous project.

Normally this inherited derived data directory isn’t a problem. For example, with errors like this, once you successfully build the project, Xcode notices its mistake and cleans up. However, in some cases you will need to trash the problematic derived data directory. In that case it’s worthwhile filing a bug against Xcode because it really should deal with this stuff. Make sure you keep a copy of the derived data directory to attach to the bug.

I see this all the time because I create a lot of test projects and they all tend to be named “xxx”, “xxy”, and so on (-: In my case I regularly trash the entire contents of

~/Library/Developer/Xcode/DerivedData/
because, if you create lots of different test projects, the directory can get big. Looking at mine today, it’s accumulated 7 GB since I last trashed it back in Sep.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I shut down Xcode and trashed the file that you indicated. I restarted Xcode and loaded the project. The same error immediately occurred again. The only enum I have is the one I listed in my original post. What could be causing this error? Shall I post the project code? It's not a big project, and can't get any bigger at this rate.


dkj


PS: I've been commenting out large sections of my code (anything involving recursion), shutting down Xcode, and then trashing the entire "DerivedData" directory. When I restart Xcode and load the project, I get that same error:


Recursive enum 'Optional<Wrapped>' is not marked 'indirect'

Here's the two files that are causing the error:

http://hatzicware.com/logic/Archive.zip

When I delete both files from the project, the error disappears. I can add Syntax.swift and compile successfully. The error occurs when I add the second file, Formula.swift. Again, the error is: Recursive enum 'Optional<Wrapped>' is not marked 'indirect'

If someone can tell me what's causing this error, I'll name my first-born child after them.


dkj

Accepted Answer

The issue you have here is that

Formula
is a recursive struct (via the
subformulas
property), which Swift doesn’t allow. The error message is completely bogus, but if you comment out enough code you’ll eventually get the right error.
/Users/quinn/Desktop/xxy/xxy/Formula.swift:11:8: error: recursive value type 'Formula' is not allowed
struct Formula {

It’s clear that Swift’s diagnostics have failed you completely here; please file a bug about that, then post your bug number, just for the record.

As to what you should do, you have the usual options when dealing with recursive data structures:

  • use a reference type

  • use an indirect enum

If someone can tell me what's causing this error, I'll name my first-born child after them.

Nah, there’s already too many Quinns in this world (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for this. I fixed it by making the Formula stored property into a String stored property, and then added a computed property that returned a Formula created from the String. It all works now.


<< Nah, there’s already too many Quinns in this world >>

OK. Irving would be annoyed at having her name changed again anyway; but as long as I'm paying her college tuition, she'll just have to put up with it.

Recursive enum 'Optional&lt;Wrapped&gt;' is not marked 'indirect'
 
 
Q