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-358] Compiler crashes when protocol defines a static method and a conforming class implements it non-statically #42978

Closed
swift-ci opened this issue Dec 23, 2015 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-358
Radar None
Original Reporter nameghino (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
Target: x86_64-apple-darwin15.2.0

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 93f7e814a0d38e6bbdf3321a626f74e7

Issue Description:

Define a protocol that contains a static function on it. Then write a protocol extension for said protocol that implements a function of the same name but without the static modifier.
When marking a class or struct as conforming to the protocol, the compiler will crash without letting the developer know the cause of the problem.
I ran into this issue by forgetting to add the modifier to the protocol extension. Moreover, the compiler wouldn't tell me that my conforming class wasn't implementing the specified method.

See the attached playground for an example.
If the function in the protocol extension has a different name, the compiler will catch it and let the developer know that the conforming class is missing said function.

Here is the stack trace that Xcode outputs:

0  swift                    0x000000010e5c0fbb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010e5c16fb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff89510eaa _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff535566a8 _sigtramp + 3389282328
4  swift                    0x000000010c887707 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 999
5  swift                    0x000000010c884ee5 swift::Lowering::SILGenModule::getWitnessTable(swift::ProtocolConformance*) + 277
6  swift                    0x000000010c8d45b0 (anonymous namespace)::SILGenType::emitType() + 1264
7  swift                    0x000000010c8d404e swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
8  swift                    0x000000010c85cbdb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 779
9  swift                    0x000000010c85d790 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 928
10 swift                    0x000000010c85db3d swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 109
11 swift                    0x000000010c6b1992 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11442
12 swift                    0x000000010c6aead3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
13 swift                    0x000000010c6ab154 main + 2324
14 libdyld.dylib            0x00007fff8c4e65ad start + 1
15 libdyld.dylib            0x0000000000000049 start + 1941019293
@gregomni
Copy link
Collaborator

Current trunk handles this gracefully:

static.swift:13:1: error: type 'TestClass' does not conform to protocol 'TestProtocol'
extension TestClass : TestProtocol { }
^
static.swift:2:17: note: protocol requires function 'foo()' with type '() -> ()'
    static func foo()
                ^
static.swift:6:10: note: candidate operates on an instance, not a type as required
    func foo() {

@swift-ci
Copy link
Collaborator Author

Comment by Nicolas Ameghino (JIRA)

Should I close this ticket?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 1, 2016

Comment by Sophie Parker (JIRA)

I have had this same bug triggered by implementing a protocol with

class func x() -> Self

without protocol extensions.

@belkadan
Copy link
Contributor

belkadan commented Jan 4, 2016

Sophie, were you using Xcode's Swift, or one of the snapshots from GitHub? If the former, I think we can call this fixed and close it.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 5, 2016

Comment by Sophie Parker (JIRA)

Ah yes that was in Xcode Swift (2.1.1). I've been away so I was unable to download the snapshot and check it there, but given it's the same bug, I agree it should be closed.

@belkadan
Copy link
Contributor

belkadan commented Jan 5, 2016

Okay, I've marked it as "resolved". Nicolas, you can close it now, or when you get a chance to test that it's fixed (which could be an Xcode beta).

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 5, 2016

Comment by Nicolas Ameghino (JIRA)

I'll close it down, test it in next Xcode beta and reopen if needs be, does that sound good?

@belkadan
Copy link
Contributor

belkadan commented Jan 5, 2016

Yep, that's fine. Thanks!

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants