'Why is Swift compiler complaining about circular reference when I comment out seemingly unrelated code?

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?



Solution 1:[1]

I did the following steps which is helps me resolve the circular reference after updated 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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amr Angry