Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
atrick opened this issue Aug 24, 2023 · 5 comments
Closed

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

atrick opened this issue Aug 24, 2023 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. ownership Feature: Ownership modifiers and semantics

Comments

@atrick
Copy link
Contributor

atrick commented Aug 24, 2023

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
@atrick atrick added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Aug 24, 2023
@atrick
Copy link
Contributor Author

atrick commented Aug 24, 2023

rdar://114395689 ([GH:#68128] [move-only] The 'consume' operator does not end the lifetime of copyable types)

@glessard
Copy link
Contributor

The same issue was reported as #68122

@atrick
Copy link
Contributor Author

atrick commented Aug 24, 2023

this looks like a different issue: #68122

@atrick atrick closed this as completed Aug 24, 2023
@atrick atrick reopened this Aug 24, 2023
@gottesmm
Copy link
Contributor

rdar://113142446

@glessard glessard added ownership Feature: Ownership modifiers and semantics and removed triage needed This issue needs more specific labels labels Sep 7, 2023
nate-chandler added a commit to nate-chandler/swift that referenced this issue Jun 5, 2024
@nate-chandler
Copy link
Contributor

Fixed by #74109 .
Regression test added in #74140 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. ownership Feature: Ownership modifiers and semantics
Projects
None yet
Development

No branches or pull requests

4 participants