Skip to content

[SR-6245] Deinit gets invoked on never-initialised object #48795

@iby

Description

@iby
Previous ID SR-6245
Radar None
Original Reporter @iby
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 8123dfa5867b9577ae49cfb6f245273e

Issue Description:

Consider the following:

class Foo
{
    init(x: UnsafeMutablePointer<Int>) {
        self.x = x
    }

    deinit {
        Swift.print("Oh boy…", self.x)
    }

    var x: UnsafeMutablePointer<Int>
}

class Bar: Foo
{
    init?(p: Int?) throws {
        if p == nil {
            Swift.print("Erroring…")
            throw E.any
        }
        var x: Int = 1
        super.init(x: &x)
    }

    convenience init?() throws {
        try self.init(p: nil)
    }
}

enum E: Error
{
    case any
}

_ = try? Bar()

It outputs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions