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-7370] Generic class conforming to @objc protocol fails assertion: "extended objc class doesn't have constant metadata?" #49918

Closed
purpleblues opened this issue Apr 6, 2018 · 7 comments
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

Comments

@purpleblues
Copy link

Previous ID SR-7370
Radar rdar://problem/39239512
Original Reporter @purpleblues
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.3(9E145), Swift 4.1

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

md5: f39162a34c6102d121b7a4579f00b4fb

cloned to:

  • SR-7372 Reject conditional conformances of @objc protocols

is duplicated by:

  • SR-857 Extensions to generic classes cannot implement Objective-C protocols

Issue Description:

import Foundation

public class FooClass<T> {

}

@objc protocol BarProtocol {

}

extension FooClass: BarProtocol where T: BarProtocol {
    
}

When the protocol used with conditional conformance for the placeholder type of generic class (T in this case) is marked @objc, the code causes Segmentation fault: 11 with error message containing call stack like below.

0  swift                    0x000000010d0deffa PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010d0de3b6 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff513a1f5a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fa4e556fda5 _sigtramp + 2484919909
4  swift                    0x0000000109cb7016 clang::CodeGen::ConstantAggregateBuilderBase::finishStruct(llvm::StructType*) + 150
5  swift                    0x00000001097e04e5 llvm::Constant* (anonymous namespace)::ClassDataBuilder::buildGlobalVariable<swift::irgen::ConstantStructBuilder>(swift::irgen::ConstantStructBuilder&, llvm::StringRef) + 597
6  swift                    0x00000001097e4942 swift::irgen::emitCategoryData(swift::irgen::IRGenModule&, swift::ExtensionDecl*) + 2418
7  swift                    0x00000001097eb3e7 swift::irgen::IRGenModule::emitGlobalDecl(swift::Decl*) + 887
8  swift                    0x00000001097eaf95 swift::irgen::IRGenModule::emitSourceFile(swift::SourceFile&, unsigned int) + 133
9  swift                    0x00000001098e353e performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1422
10 swift                    0x000000010973edce performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 38110
11 swift                    0x0000000109733e64 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
12 swift                    0x00000001096e88b5 main + 18917
13 libdyld.dylib            0x00007fff51093015 start + 1

The issue disappears when @objc is removed from the protocol

@belkadan
Copy link
Contributor

belkadan commented Apr 6, 2018

With assertions:

Assertion failed: (metadata && "extended objc class doesn't have constant metadata?"), function emitCategory, file /Volumes/Data/swift-public/swift/lib/IRGen/GenClass.cpp, line 1322.

I don't think conditional conformances to @objc protocols should be accepted, but even dropping that part causes the assertion failure for me. I'll clone out a separate bug for that.

@swift-ci create

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 9, 2018

By "dropping that part", I think @belkadan means removing the where T: BarProtocol since just extension FooClass: BarProtocol triggers the same assertion. @jckarter, thoughts?

@jckarter
Copy link
Member

jckarter commented Apr 9, 2018

I think that's a dup of another issue, where we haven't really implemented adding ObjC methods or protocol extensions for generic classes, since there's no single class object to generate a "category" for.

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 10, 2018

Ah, thanks! I think I found it. It does appear to be resolved if the (non-conditional) conformance is moved to the type declaration instead of the extension.

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 10, 2018

Actually, I changed my mind: the example in that issue gives a diagnostic "@objc is not supported within extensions of generic classes or classes that inherit from generic classes", but that's only because the protocol defines a requirement. We should have an error for this case too.

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 10, 2018

#15842

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 13, 2018

db8b98b

@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
Projects
None yet
Development

No branches or pull requests

4 participants