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

[SR-13564] ObjectIdentifier's equal has an unexpected result #56002

Open
swift-ci opened this issue Sep 18, 2020 · 3 comments
Open

[SR-13564] ObjectIdentifier's equal has an unexpected result #56002

swift-ci opened this issue Sep 18, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13564
Radar rdar://problem/69169351
Original Reporter 酷酷的哀殿 (JIRA User)
Type Bug

Attachment: Download

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

md5: b66954dda298d0c551eb157c90071d53

Issue Description:

//代码占位符
    func makeIdentifier(input: Int) -> ObjectIdentifier {
        ObjectIdentifier(NSNumber(value:input));
    }
    
    let a = makeIdentifier(input: Int.min);
    let b = makeIdentifier(input: Int.max);
    print(a == b) // print: true

we expected it is false

Reason:

The first IntegerRef will be free after ObjectIdentifier.init, so the second will use the same heap memory.

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Kyle Macomber (JIRA)

We should document that ObjectIdentifier are only unique while the object is alive.

@lorentey
Copy link
Member

ObjectIdentifier is only guaranteed unique as long as the underlying object exists – when the instance gets deallocated, its object identifier may be reused for a different object. (Internally, objects are identified by their memory location.)

This works as intended, although the documentation ought to describe this fact.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants