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-4130] Extensions of generic subclasses of NSObject defined in Swift crash in IRGen #46713

Closed
NachoSoto opened this issue Mar 1, 2017 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-4130
Radar rdar://problem/21216149
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Duplicate
Environment

Version 8.2.1 (8C1002)
Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, IRGen
Assignee @slavapestov
Priority Medium

md5: 8601fb47c82e99a3b2955783065368de

duplicates:

  • SR-2078 Conformance to an @objc protocol by a generic type in an extension crashes the compiler

Issue Description:

Compile the following code:

final class InfiniteScrollingCollectionView<T>: UIView, UICollectionViewDataSource {
    init() {
        self.sections = Property(value: [])
        
        super.init(frame: .zero)

        self.addSubview(self.collectionView)
        
        self.collectionView.dataSource = self
        self.collectionView.delegate = self
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: -
    
    private let sections: Property<[Section<T>]>
    
    // MARK: -
    
    private let collectionView: UICollectionView = {
        let view = UICollectionView()
        
        return view
    }()
    
    // MARK: - UICollectionViewDataSource
    
    @objc func numberOfSections(in collectionView: UICollectionView) -> Int {
        return self.sections.value.count
    }
    
    @objc func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.sections.value[section].size
    }
    
    @objc func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        return collectionView.dequeueReusableCell(withReuseIdentifier: "TODO", for: indexPath)
    }
}

fileprivate enum Section<T> {
    case loaded(Data)
    case notLoaded(expectedCount: Int)
    
    var size: Int {
        switch self {
        case let .loaded(data):
            return data.count
            
        case let .notLoaded(count):
            return count
        }
    }
}

extension InfiniteScrollingCollectionView: UICollectionViewDelegate {
    
}

struct Property<T> {
    let value: T
}

Removing the `UICollectionViewDelegate` extension is a workaround. Looks like this is an issue with extensions on generic types that conform to Objective-C protocols.

@slavapestov
Copy link
Member

Classes with generic ancestry do not have static metadata. We have to refactor how we emit Objective-C categories so that we can emit code to register them at runtime in this case.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

3 participants