2 Replies
      Latest reply on Mar 25, 2020 2:29 AM by eskimo
      phil82 Level 1 Level 1 (0 points)

        ```swift

                    public static func instance(by queryItem: [String: String]) -> Self? {

                        let items = queryItem.map({ ($0.key.lowercased(), $0.value) })

                        let dict = [String: String](uniqueKeysWithValues: items)

         

                        var _url: String?

                        if let value = dict["url"] {

                            _url = value

                        }

         

                        var title: String?

                        if let value = dict["title"] {

                            title = value

                        }

                        guard

                            let url = _url

                        else { return nil }

                        return PRWebview(

                            url: url,

                            title: title

                        )

                    }

        ```

        When I archive the iOS project, will faild with error: Segmentation fault: 11

         

        ```

        1. While running pass #153921 SILFunctionTransform "DCE" on SILFunction "@$s23URLNavigatorExt_Example6RouterO9PRWebviewV8instance2byAESgSDyS2SG_tFZ".

        for 'instance(by:)' (at /Users/phil/Documents/WorkSpace/ky_tech/URLNavigatorExt/Example/URLNavigatorExt/generated/Router.generated.swift:989:20)

        0  swift                    0x0000000104fdea63 PrintStackTraceSignalHandler(void*) + 51

        1  swift                    0x0000000104fde236 SignalHandler(int) + 358

        2  libsystem_platform.dylib 0x00007fff5b7bfb5d _sigtramp + 29

        3  libsystem_platform.dylib 0x0000000106644e00 _sigtramp + 2867352256

        4  swift                    0x000000010134c370 (anonymous namespace)::DCE::markControllingTerminatorsLive(swift::SILBasicBlock*) + 800

        5  swift                    0x000000010134bca2 (anonymous namespace)::DCE::markValueLive(swift::SILNode*) + 466

        6  swift                    0x00000001013495e8 (anonymous namespace)::DCE::run() + 2728

        7  swift                    0x00000001012d0f3e swift::SILPassManager::execute() + 4606

        8  swift                    0x0000000100f2f96b swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 6379

        9  swift                    0x0000000100c27ec5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 33925

        10 swift                    0x0000000100c1c234 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820

        11 swift                    0x0000000100ba9733 main + 1219

        12 libdyld.dylib            0x00007fff5b5d43d5 start + 1

        13 libdyld.dylib            0x0000000000000056 start + 2762128514

        error: Segmentation fault: 11 (in target 'URLNavigatorExt_Example' from project 'URLNavigatorExt')

        ```

         

        If I change the code

        ```swift

                        var _url: String?

                        if let value = dict["url"] {

                            _url = value

                        }

        // to

                        var _url: String? = dict["url"]

        ```

        This archive will be successful

         

        I create a demo project

        https://github.com/philCc/URLNavigatorExt.git

        branch:Segmentation_fault_11

        • Re: Segmentation fault: 11
          Claude31 Level 8 Level 8 (9,145 points)

          Did you test :

                          var _url: String? = nil
                          if let value = dict["url"] {
                              _url = value
                          }

           

          Why do you declare url as optional at first ?

           

          Would this work:

                          var _url: String = ""
                          if let value = dict["url"] {
                              _url = value
                          }
          • Re: Segmentation fault: 11
            eskimo Apple Staff Apple Staff (13,905 points)

            I create a demo project

            Can you reproduce the problem without CocoaPods in the mix?


            In general, the Swift compiler should never crash, and thus this is definitely bugworthy.  I downloaded your project to see if it still crashes with Xcode 11.4 — just released, and with tonnes of bug fixes for problems like these — but then I ran into CocoaPods.

            Share and Enjoy

            Quinn “The Eskimo!”
            Apple Developer Relations, Developer Technical Support, Core OS/Hardware
            let myEmail = "eskimo" + "1" + "@apple.com"