Skip to content

[SR-3471] NSHashTable objects retrieved from setRepresentation behave differently on debug / release #4426

Open
@swift-ci

Description

@swift-ci
Previous ID SR-3471
Radar rdar://problem/31857596
Original Reporter ian.guedesmaia (JIRA User)
Type Bug

Attachment: Download

Environment

XCode 8.2, iOS 9, iOS 10

Additional Detail from JIRA
Votes 0
Component/s Compiler, Foundation
Labels Bug, OptimizedOnly
Assignee ian.guedesmaia (JIRA)
Priority Medium

md5: 48c176c2bd03a42277095b94ef0e9914

Issue Description:

The code below behaves differently on debug builds and on release builds. I'm not sure about the specific configuration that is causing it, but I can reproduce it quite easily.

@objc
protocol Observer: NSObjectProtocol {
    func didUpdate()
}

class UserSession: NSObject {
    fileprivate let observers: NSHashTable<Observer> = NSHashTable.weakObjects()

    fileprivate func notifyObserversAboutUpdate() {
        for observer in self.observers.setRepresentation {
            //this cast succeeds on debug but fails on release
            if let observer = observer as? Observer {
                observer.didUpdate()
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions