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?