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

Runtime Crash in nested type erased protocol wrapper

    XMLWordPrintable

    Details

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

      iOS and macOS playground or iPhone 5, iOS 10.3.1 simulator.

      All tested on macOS Mojave

      Description

      The following code crashes in swift_retain when run in

      • an iOS or macOS playground
      • iPhone 5, iOS 10.3.1 simulator

      I could reproduce the bug on both Xcode 10.0 and Xcode 10.1 beta 2.

      public protocol P {
          associatedtype Key
          func f <T> () -> T? where T == Key
      }
      
      public struct AnyP <Key>: P {
          let _f: () -> Key?
          
          public init <S: P> (_ s: S) where S.Key == Key {
              _f = s.f
          }
          
          public init (_ f: @escaping () -> Key?) {
              _f = f
          }
          
          public func f() -> Key? {
              return _f()
          }
      }
      let anyP = AnyP<String>( { return nil })
      let nestedAnyP = AnyP(anyP)
      anyP.f() // This works
      nestedAnyP.f() // This crashes
      

      I have attached a sample single view iOS project to reproduce the crash.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            sebastiangrail Sebastian Grail
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: