Uploaded image for project: 'Swift'
  1. Swift
  2. SR-358

Compiler crashes when protocol defines a static method and a conforming class implements it non-statically

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

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

      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
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              nameghino Nicolas Ameghino
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: