# Two convenience initializers can call each other forever

**URL:** <https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020>\
**Category:** Using Swift\
**Tags:** bug, init\
**Created:** [February 26, 2026, 1:20pm UTC](https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020 "2026-02-26T13:20:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nevan](https://avatars.discourse-cdn.com/v4/letter/n/f04885/32.png) [@nevan](https://forums.swift.org/u/nevan)\
**Post date:** [February 26, 2026, 1:20pm UTC](https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020/1 "2026-02-26T13:20:29Z")

</div>

I saw this other discussion, where a convenience init was allowed to call itself:

> [@Circular init pattern not caught by compiler](https://forums.swift.org/t/circular-init-pattern-not-caught-by-compiler/55249):
>
> class Location: NSManagedObject, Decodable { var country: String = "" required convenience init(from decoder: Decoder) throws { try self.init(from: decoder) let container = try decoder.container(keyedBy: CodingKeys.self) self.country = try container.decode(String.self, forKey: .country) } enum CodingKeys: String, CodingKey { case country } } I am not sure why this is compiling, the initializer is calling itself in an infinite l…

I’m not sure if this is the same issue. Two convenience inits calling each other wasn’t flagged by the compiler, despite the init chain never ending in a designated initializer. Xcode 26.2, Swift 5

```swift
class Person {
    var name: String
    var age: Int
    init(name: String, age: Int) {
        self.name = name
        self.age = age
    }
    convenience init(name: String) {
        self.init(age: 23)
        self.name = name
    }
    convenience init(age: Int) {
        self.init(name: "bob")
        self.age = age
    }
}
// spins forever
let bob = Person(name: "bob")

```

---

<div class="post-metadata">

**Author:** ![Hacksaw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hacksaw/32/32775_2.png) [@Hacksaw](https://forums.swift.org/u/Hacksaw)\
**Post date:** [February 26, 2026, 8:25pm UTC](https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020/2 "2026-02-26T20:25:10Z")

</div>

FWIW, also true in Xcode 26.4, Swift 6 mode. Xcode made a few thousand stack frames trying to do it before somehow hitting a bad access. Maybe a stack smash?

Ooooo, in thinking about this, having flexibility as a goal makes it difficult to check this without simply trying it, since you might want to have a particular convenience init call another convenience init... so I guess you'd need to have to check that somewhere in a chain you'd reach a designated init.

If I were designing a language, I'd probably opt for a rule that said convenience inits must call designated inits, despite the possible limitation that would impose. But then, I'm not anyone's wise first choice for language design.

---

<div class="post-metadata">

**Author:** ![John\_McCall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/john_mccall/32/1351_2.png) [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Post date:** [February 26, 2026, 8:34pm UTC](https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020/3 "2026-02-26T20:34:54Z")

</div>

I don't really see this as a language defect; it's just a novel way to write an infinite recursion, like you can in any other language. Would it be nice if Swift caught this? Sure, but only in the same way that it'd be nice if it caught any other infinite recursion.

---

<div class="post-metadata">

**Author:** ![Hacksaw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hacksaw/32/32775_2.png) [@Hacksaw](https://forums.swift.org/u/Hacksaw)\
**Post date:** [February 26, 2026, 9:19pm UTC](https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020/4 "2026-02-26T21:19:08Z")

</div>

Reasonable. My preference is for a language to gently discourage tricksy constructions, as they often lead to "clever code", i.e. hard to debug. That said, I'd hate to also discourage a clear and understandable construction.

---

<div class="post-metadata">

**Author:** ![dratsie](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@dratsie](https://forums.swift.org/u/dratsie)\
**Post date:** [February 26, 2026, 9:31pm UTC](https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020/5 "2026-02-26T21:31:42Z")

</div>

I would agree that infinite recursion like this is in the hands of the programmer.

I appreciate that this is a forced example however I would expect both convenience initialisers to be calling the designated initialiser with a fixed parameter value; so no recursion. Up to the programmer to construct the initialisers into a pyramid.

---

<div class="post-metadata">

**Author:** ![nevan](https://avatars.discourse-cdn.com/v4/letter/n/f04885/32.png) [@nevan](https://forums.swift.org/u/nevan)\
**Post date:** [February 26, 2026, 10:09pm UTC](https://forums.swift.org/t/two-convenience-initializers-can-call-each-other-forever/85020/6 "2026-02-26T22:09:33Z")

</div>

I don’t think it’s a language defect either. But I do think the compiler should catch the fact that the init rule about all init paths leading to a designated init is being broken. Maybe the other init rules (like convenience inits not calling up to the superclass) are just easier to detect than the ones about init paths.
