Skip to content

[SR-13746] Throwing initializers vs. deinit: breaking change in Swift 5.3.1 #56143

@groue

Description

@groue
Previous ID SR-13746
Radar rdar://problem/70379842
Original Reporter @groue
Type Bug
Status Resolved
Resolution Won't Do
Environment

Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)

Xcode version 12.2 beta 3 (12B5035g)

macOS 10.15.6 (19G2021)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: e915273ef3ea66ad1e41b2d1515cca89

Issue Description:

Hello, the compiler Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8) that ships with Xcode version 12.2 beta 3 (12B5035g) has introduced a breaking change.

The program below has changed its behavior. In previous Swift versions, the deinitializer would not run, and the program would print nothing. In Swift 5.3.1 / Xcode 12.2 beta 3, the deinitializer runs, and the program prints "deinit".

struct TestError: Error { }
class Inner {
    init() throws { }
}
class Test {
    private let inner: Inner
    init() throws {
        inner = try Inner()
        throw TestError()
    }
    deinit { print("deinit") }
}
do { _ = try Test() }
catch { }

I can not tell if this is an intended change, or not.

Still, this is a breaking change. It affects the GRDB library, because an error during the initialization of an SQLite database closes the connection twice on Xcode 12.2 beta 3, and this triggers an assertion failure. See https://github.com/groue/GRDB.swift/blob/v5.0.2/GRDB/Core/SerializedDatabase.swift#L17-L69

I do not know if I should adapt the program for this new behavior, or wait for this breaking change to be resolved. Any clue on this question would be appreciated!

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions