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

Failed to demangle witness for associated type (CF_ENUM)

    XMLWordPrintable

    Details

      Description

      The Swift 5 toolchain includes a regression that results in a runtime error;

      failed to demangle witness for associated type ....
      Abort trap: 6
      

      This occurs when a generic type references a nested associated type that is a CF_ENUM / NS_ENUM from Foundation (or possibly another module??). The issue does not occur within Swift 4.2.

      Consider the following;

      protocol CommandTypes {
          associatedtype Result
          associatedtype Message
      }
      
      struct EnumCommand: CommandTypes {
          typealias Result = ComparisonResult
          typealias Message = String
      }
      
      struct Command<T: CommandTypes> {
          var result: T.Result?
          var message: T.Message?
      }
      

      ❌In Swift 5, declaring an array which references an associated type of CF_ENUM results in abort Trap 6. e.g.

      let _ = [Command<EnumCommand>]()
      

      ✅Declaring an array with other types is fine;

      struct BasicCommand: CommandTypes {
          typealias Result = String
          typealias Message = String
      }
      
      let _ = [Command<BasicCommand>]()
      

      ✅One workaround is to access the CF_ENUM type at least once prior e.g.

      let _ = [ComparisonResult.self] as [Any]
      let _ = [Command<EnumCommand>]()
      

        Attachments

          Activity

            People

            Assignee:
            DougGregor Doug Gregor
            Reporter:
            swhitty Simon Whitty
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: