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-2791] exc_bad_access if I try to inherit generic swift class from NSObject #45395

Closed
swift-ci opened this issue Sep 29, 2016 · 7 comments
Closed

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Sep 29, 2016

Previous ID SR-2791
Radar None
Original Reporter Vasili.Silin (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.0Regression, RunTimeCrash
Assignee @slavapestov
Priority Medium

md5: 2dfbdebd7b3b6afb8df842a835d375a6

duplicates:

  • SR-2586 Final keyword made ObjC based generic type work incorrectly

Issue Description:

Let me share my code sample.
I have protocol:

protocol PSession {
    
    associatedtype ManagerType
    
    var manager: ManagerType { get }
    
}

Base class.

import Foundation

class BaseSession<ConcreteManagerType> : NSObject, PSession {
    
    typealias ManagerType = ConcreteManagerType
    
    let manager: ConcreteManagerType
    
    let bindingStorage: BindingStorage
    
    init(manager: ConcreteManagerType) {
        self.manager = manager
        self.bindingStorage = BindingStorage()
    }
    
}

If I remove NSObject inheritance everything is fine and works.
If not I can see exc_bad_access (image and output from XCode 8 Swift 3):
image: http://screencast.com/t/UG70X24fd
some output:
objc[43570]: CLASS: realizing class 'TtGC7Habitat11BaseSessionPS_26PDeviceProvisioningManager_' 0x120736030 0x1207360d0 #0
objc[43570]: CLASS: realizing class 'TtGC7Habitat11BaseSessionPS_26PDeviceProvisioningManager_' (meta) 0x1207360a8 0x120736118 #0
objc[43570]: CLASS: methodizing class 'TtGC7Habitat11BaseSessionPS_26PDeviceProvisioningManager_' (meta)
objc[43570]: CLASS: methodizing class 'TtGC7Habitat11BaseSessionPS_26PDeviceProvisioningManager_'
objc[43570]: CLASS: realizing class 'Habitat.DeviceProvisioningSession' 0x109841d50 0x1097f9c88 #0
objc[43570]: CLASS: realizing class 'Habitat.DeviceProvisioningSession' (meta) 0x109841d08 0x1097f9b98 #0
objc[43570]: CLASS: methodizing class 'Habitat.DeviceProvisioningSession' (meta)
objc[43570]: CLASS: methodizing class 'Habitat.DeviceProvisioningSession'

If it help, here is a part of DeviceProvisioningSession class:

import Foundation

class DeviceProvisioningSession : BaseSession<PDeviceProvisioningManager>, PDeviceProvisioningSession {
    
    fileprivate(set) var currentProvisioningProfile: DeviceProvisionProfile
    
    override init(manager: PDeviceProvisioningManager) {
        self.currentProvisioningProfile = (nil, nil, nil)
        
        super.init(manager: manager)
    }
    
    // MARK: PDeviceProvisioningSession

    //implementation here
    
    // MARK: END PDeviceProvisioningSession
    
}

Everything was ok with Swift 2.3, but I receiving exc_bad_access with Swift 3.

As I mentioned above, everything is fine in Swift 3, if I remove NSObject inheritance:
Base class.

import Foundation

class BaseSession<ConcreteManagerType> : PSession {
    
    typealias ManagerType = ConcreteManagerType
    
    let manager: ConcreteManagerType
    
    let bindingStorage: BindingStorage
    
    init(manager: ConcreteManagerType) {
        self.manager = manager
        self.bindingStorage = BindingStorage()
    }
    
}

So, it's seems like Swift 3 has an issue with NSObject inheritance and Swift Generics.

Best regards,
Vasili Silin.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Sep 29, 2016

Can you attach your entire project, or a small project that reproduces this? That way we can be sure we're looking at the same problem.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Sep 29, 2016

Comment by Vasili Silin (JIRA)

Sure. I can create small project.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Sep 29, 2016

Comment by Vasili Silin (JIRA)

I attached test project. ExcBadAccessInheritance.zip

@belkadan
Copy link
Contributor

@belkadan belkadan commented Sep 29, 2016

Crash is in swift_initClassMetadata_UniversalStrategy.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Sep 29, 2016

Seems to be fixed in master. @jckarter, @slavapestov, did anything change here recently?

@jckarter
Copy link
Member

@jckarter jckarter commented Sep 29, 2016

Yeah, this looks like a bug Slava fixed recently.

@slavapestov
Copy link
Member

@slavapestov slavapestov commented Sep 29, 2016

It should be fixed in swift-3.0-branch too: 8d3526e

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants