6

Creating a brand new macOS Command Line Tool project in Xcode Version 13.3 (13E113), and replacing the contents of main.swift with the following code:

import Foundation

enum StructA {
    // case case1(value: StructB)
    case case2(expr: StructB)
}

indirect enum StructB {
    case case3
    case case4(expr: StructB)
}

Results in the following compile-time error:

<unknown>:0: error: circular reference
/Users/alextj/projects/TestProject/main.swift:8:15: note: through reference here
indirect enum StructB {
              ^
<unknown>:0: note: through reference here

However, if you uncomment the case1 line, then the circular reference error goes away!

So the following code compiles without errors:

import Foundation

enum StructA {
    case case1(value: StructB)
    case case2(expr: StructB)
}

indirect enum StructB {
    case case3
    case case4(expr: StructB)
}

Why?

Why does commenting out case1 cause a circular reference?

Alex
  • 1,574
  • 17
  • 36

1 Answers1

0

I did the following steps which helped me resolve the circular reference after updating to Xcode 13.3.1:

1- Clean project.

2- Clean derived data.

3- Change project Build Setting SWIFT_COMPILATION_MODE from Incremental to the Whole Module.

https://forums.swift.org/t/strange-enum-circular-reference-error-in-xcode-13-3/56721/2

Amr Angry
  • 3,711
  • 1
  • 45
  • 37
  • 2
    Thanks for the answer Amr! I tried your steps, also on Xcode 13.3.1, but I still get the circular reference error :( – Alex May 10 '22 at 18:02
  • it's one of the weird errors i have ever seen, I hope you resolved soon. sorry I couldn't help match since it's not available anymore in my project – Amr Angry May 10 '22 at 19:57