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-6001] Protocols inheriting from classes #48558

Closed
swift-ci opened this issue Sep 26, 2017 · 6 comments
Closed

[SR-6001] Protocols inheriting from classes #48558

swift-ci opened this issue Sep 26, 2017 · 6 comments

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 26, 2017

Previous ID SR-6001
Radar None
Original Reporter mdmorris (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 4

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

md5: e5e571eae12cbeb9d9440144200dc67c

duplicates:

  • SR-6000 Let protocols inherit from class types

Issue Description:

class Strawman {
}

protocol Fooable where Self: Strawman {
func foo()
}

// This doesn't seem like an especially useful thing to do
// and might reasonably be an error, but I think hard
// crashing the compiler is a bit much.
extension Strawman: Fooable {
public func foo() { print("Foo!") }
}

@belkadan
Copy link
Contributor

belkadan commented Sep 27, 2017

   Assertion failed: (hasConformanceInSignature(inProtocol->getRequirementSignature(), subjectType, conformingProto) && "missing explicit conformance in requirement signature"), function operator(), file /Volumes/Data/swift-public/swift/lib/AST/GenericSignature.cpp, line 854.

7  swift                    0x00000001066223be std::__1::__function::__func<swift::GenericSignature::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*, swift::ModuleDecl&)::$_11, std::__1::allocator<swift::GenericSignature::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*, swift::ModuleDecl&)::$_11>, void (llvm::ArrayRef<swift::Requirement>, swift::GenericSignatureBuilder::RequirementSource const*, swift::ProtocolDecl*, swift::Type, swift::ProtocolDecl*)>::operator()(llvm::ArrayRef<swift::Requirement>&&, swift::GenericSignatureBuilder::RequirementSource const*&&, swift::ProtocolDecl*&&, swift::Type&&, swift::ProtocolDecl*&&) + 1422
8  swift                    0x000000010662226a std::__1::__function::__func<swift::GenericSignature::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*, swift::ModuleDecl&)::$_11, std::__1::allocator<swift::GenericSignature::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*, swift::ModuleDecl&)::$_11>, void (llvm::ArrayRef<swift::Requirement>, swift::GenericSignatureBuilder::RequirementSource const*, swift::ProtocolDecl*, swift::Type, swift::ProtocolDecl*)>::operator()(llvm::ArrayRef<swift::Requirement>&&, swift::GenericSignatureBuilder::RequirementSource const*&&, swift::ProtocolDecl*&&, swift::Type&&, swift::ProtocolDecl*&&) + 1082
9  swift                    0x0000000106620bb9 swift::GenericSignature::getConformanceAccessPath(swift::Type, swift::ProtocolDecl*, swift::ModuleDecl&) + 681
10 swift                    0x000000010668b1ee swift::SubstitutionMap::lookupConformance(swift::CanType, swift::ProtocolDecl*) const + 270
11 swift                    0x00000001066218cd bool llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>::callback_fn<swift::GenericSignature::getSubstitutions(swift::SubstitutionMap const&, llvm::SmallVectorImpl<swift::Substitution>&) const::$_8>(long, swift::Type, llvm::ArrayRef<swift::Requirement>) + 397
12 swift                    0x000000010661e836 swift::GenericSignature::enumeratePairedRequirements(llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>) const + 1110
13 swift                    0x000000010661fdf4 swift::GenericSignature::getSubstitutions(swift::SubstitutionMap const&, llvm::SmallVectorImpl<swift::Substitution>&) const + 36
14 swift                    0x0000000106365959 (anonymous namespace)::RequirementMatch::getWitness(swift::ASTContext&, (anonymous namespace)::RequirementEnvironment&&) const + 57
15 swift                    0x000000010636a5b6 (anonymous namespace)::ConformanceChecker::recordWitness(swift::ValueDecl*, (anonymous namespace)::RequirementMatch const&, (anonymous namespace)::RequirementEnvironment&&) + 262
16 swift                    0x00000001063682b9 (anonymous namespace)::ConformanceChecker::resolveWitnessViaLookup(swift::ValueDecl*) + 4153
17 swift                    0x000000010635f023 (anonymous namespace)::MultiConformanceChecker::checkAllConformances() + 3571
18 swift                    0x000000010635ff6f swift::TypeChecker::checkConformancesInContext(swift::DeclContext*, swift::IterableDeclContext*) + 2735
19 swift                    0x000000010633197c (anonymous namespace)::DeclChecker::visitExtensionDecl(swift::ExtensionDecl*) + 572
20 swift                    0x00000001063217b9 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 233
21 swift                    0x00000001063216c4 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 100
22 swift                    0x00000001063ac5ea swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1754
23 swift                    0x0000000106053cdf swift::CompilerInstance::performSema() + 3663
24 swift                    0x00000001055c19de performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1742
25 swift                    0x00000001055c040a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3530
26 swift                    0x00000001055813e0 main + 3360
27 libdyld.dylib            0x00007fff5a6e3145 start + 1
28 libdyld.dylib            0x000000000000000f start + 2777796299
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin17.0.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name main -o /var/folders/g6/djx_5sv95d90j_6xgcfknlhc0000gn/T/--108f60.o 
1.  While type-checking extension of Strawman at <stdin>:9:1

@DougGregor, @slavapestov, sound familiar?

@slavapestov
Copy link
Member

slavapestov commented Sep 27, 2017

We haven't implemented protocols inheriting from classes yet, however it is a part of SE-0156 and we should do it eventually. I'll take this.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 1, 2018

Comment by Erich Graham (JIRA)

Looks like SE-0156's status is Implemented. Is this bug still slated to be done then? Relevant forum post: https://forums.swift.org/t/defining-protocols-for-certain-class-types-only/8702/11

@itaiferber
Copy link
Contributor

itaiferber commented Mar 1, 2018

I think we just forgot to update the status of this, no? Works fine for me with Swift 4.1:

class Strawman {
}
protocol Fooable where Self: Strawman {
    func foo()
}

extension Strawman: Fooable {
    public func foo() { print("Foo!") }
}

let s = Strawman()
s.foo()

prints Foo!

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 1, 2018

Comment by Erich Graham (JIRA)

This code does not work, Swift 4.1:

protocol HeaderViewing where Self: UIView {
    func set(title: String)
}

class MyView: UIView, HeaderViewing {
    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func set(title: String) {

    }
}

let myView: HeaderViewing = MyView(frame: .zero)
myView.set(title: "Hello")

myView.removeFromSuperview() /** Value of type 'HeaderViewing' has no member 'removeFromSuperview' */

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 11, 2018

Comment by Erich Graham (JIRA)

Any idea if this bug will be resolved in 4.2 or 5.0? This forces the above example to define the variable as `let myView: HeaderViewing & UIView` when it should work as written, `let myView: HeaderViewing`

@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