Skip to content

The 'consume' operator does not end the lifetime of copyable types #68128

@atrick

Description

@atrick

See https://forums.swift.org/t/should-deinit-be-called-after-explicit-consume-of-reference-type/66920

consumereference.swift.txt

class Object {
    deinit { print("deinit object") }
}

struct Noncopyable: ~Copyable {
    deinit { print("deinit noncopyable") }
}

func testDeinitAfterConsume() {
    do {
        let object = Object()
        print("before consume")
        _ = consume object
        print("after consume")
    }
    
    print()
    
    do {
        let noncopyable = Noncopyable()
        print("before consume")
        _ = consume noncopyable
        print("after consume")
    }
}

testDeinitAfterConsume()

The consume operator ends the variable's lifetime. The following behavior is incorrect and reflects the fact that the operator is not fully implemented.

before consume
after consume
deinit object

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.ownershipFeature: Ownership modifiers and semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions