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

Crash when attempting to assign an unbound method from a protocol

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler
    • Environment:

      macOS 10.14.6
      Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
      Target: x86_64-apple-darwin18.7.0

      Description

      The following code will crash the compiler (Swift 5.1.2):

      protocol S {
      }
      extension S {
        func a() {}
      }
      let f = S.a
      

      Of course, this would work perfectly if `S` was a struct (or class) rather than a protocol. If the same behavior is not meant to be supported, then the compiler should issue an error message at line 6.

      Here's my stack dump:

      Stack dump:
      0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret main.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name main 
      0  swift                    0x0000000109c4ea13 PrintStackTraceSignalHandler(void*) + 51
      1  swift                    0x0000000109c4e1e6 SignalHandler(int) + 358
      2  libsystem_platform.dylib 0x00007fff6836fb5d _sigtramp + 29
      3  libsystem_platform.dylib 0x0000000000000001 _sigtramp + 2546533569
      4  swift                    0x0000000105d066aa swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 58794
      5  swift                    0x0000000105cf86bc swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 1468
      6  swift                    0x0000000105cf95e3 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 5347
      7  swift                    0x0000000105d0c876 void llvm::function_ref<void (swift::Expr*)>::callback_fn<swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_15>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_15)::'lambda'(swift::Expr*)>(long, swift::Expr*) + 38
      8  swift                    0x0000000105d0cb8d swift::Lowering::SILGenFunction::emitOpenExistentialExprImpl(swift::OpenExistentialExpr*, llvm::function_ref<void (swift::Expr*)>) + 685
      9  swift                    0x0000000105cff974 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 30836
      10 swift                    0x0000000105cf7f23 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 131
      11 swift                    0x0000000105ceb31c swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 268
      12 swift                    0x0000000105c9221d swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 93
      13 swift                    0x0000000105c949af swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1087
      14 swift                    0x0000000105c93806 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
      15 swift                    0x0000000105c952b1 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1313
      16 swift                    0x0000000105899795 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 30885
      17 swift                    0x000000010588e6e4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
      18 swift                    0x000000010581bbe3 main + 1219
      19 libdyld.dylib            0x00007fff681843d5 start + 1
      20 libdyld.dylib            0x000000000000000a start + 2548546614
      Segmentation fault: 11
      mipha-1:Algo alvae$ swift --version
      Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
      Target: x86_64-apple-darwin18.7.0
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Alvae Dimitri Racordon
              Reporter:
              Alvae Dimitri Racordon
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: