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

Missing throws in @objc protocol conformance with parameter segfaults

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
    • Environment:

      Xcode 11.2 (11B52)

      macOS 10.14.6 (18G103)

      Description

      When forgetting the `throws` keyword when conforming to an @objc protocol the compiler segfaults iff the method has a parameter:

       

      import Foundation
      
      public final class Kermit: NSObject, Muppet {
          public func name(some: String) -> String { "Kermit" }
      }
      
      @objc(Muppet)
      public protocol Muppet: AnyObject {
          @objc optional func name(some: String) throws -> String
      }

       

      Removing the parameter from the function (and protocol) and it compiles. Adding the `throws` to the implementation also works.

      A sample project is included for your entertainment pleasure.

      crash log:

      1.	While generating Objective-C header
      2.	While printing 'Kermit' (in module 'ThrowingSegFault')
      0  swift                    0x000000010ab30a13 PrintStackTraceSignalHandler(void*) + 51
      1  swift                    0x000000010ab301e6 SignalHandler(int) + 358
      2  libsystem_platform.dylib 0x00007fff7ec1db5d _sigtramp + 29
      3  libsystem_platform.dylib 0x00007ff2c80201b8 _sigtramp + 1228940920
      4  swift                    0x0000000106a38760 void (anonymous namespace)::ObjCPrinter::printMembers<false, swift::IteratorRange<swift::DeclIterator> >(swift::IteratorRange<swift::DeclIterator>&&) + 560
      5  swift                    0x0000000106a3594c swift::ASTVisitor<(anonymous namespace)::ObjCPrinter, void, void, void, void, void, void>::visit(swift::Decl*) + 7196
      6  swift                    0x0000000106787a3c bool llvm::function_ref<bool (llvm::raw_pwrite_stream&)>::callback_fn<printAsObjCIfNeeded(llvm::StringRef, swift::ModuleDecl*, llvm::StringRef, bool)::$_7>(long, llvm::raw_pwrite_stream&) + 6252
      7  swift                    0x000000010674a729 swift::withOutputFile(swift::DiagnosticEngine&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>) + 2569
      8  swift                    0x00000001067848a3 emitAnyWholeModulePostTypeCheckSupplementaryOutputs(swift::CompilerInstance&, swift::CompilerInvocation&, bool) + 451
      9  swift                    0x000000010677c44a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 34138
      10 swift                    0x00000001067706e4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
      11 swift                    0x00000001066fdbe3 main + 1219
      12 libdyld.dylib            0x00007fff7ea323d5 start + 1
      error: Segmentation fault: 11 (in target 'ThrowingSegFault' from project 'ThrowingSegFault')

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            tkrajacic Thomas Krajacic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: