Skip to content

Instantly share code, notes, and snippets.

@ralfebert
Created June 12, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfebert/0821a1c4f1d34e048508af89e258190b to your computer and use it in GitHub Desktop.
Save ralfebert/0821a1c4f1d34e048508af89e258190b to your computer and use it in GitHub Desktop.

FB9165511: Swift compiler accepts an invalid circular reference in some conditions

The following code example doesn't compile because of the circular reference. Except if you uncomment the line that uses the weak self. It's still an invalid circular reference, but all of a sudden the compiler accepts it. Happens with Xcode 12.5 and 13 Beta 1.

class Flupp {
    init() {
        print("Flupp!")
    }
    deinit {
        print("Deflupp!")
    }
}

struct Boing {
    var boing: () -> Void
}

class Schnuck {
    init() {
        var boing = Boing { [weak self] in
            print(boing)
            // <--- Uncomment this to make it compile
            // guard let self = self else { return }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment