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

Runtime: Unable to Demangle Type of Field

    XMLWordPrintable

    Details

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

      2,4 GHz Intel Core i7 MacBook Pro (17-inch, Late 2011) running macOS High Sierra 10.13.5 (17F77), Xcode 10.0 beta 6 (10L232m) and Swift 4.2 (swiftlang-1000.0.36 clang-1000.0.4).

      Description

      Given the following code:

      @inlinable public func zipLongest <Collection1, Collection2> (_ collection1: Collection1, _ collection2: Collection2) -> ZipLongest2Collection<Collection1, Collection2> {
        return ZipLongest2Collection(_collection1: collection1, _collection2: collection2)
      }
      
      public struct ZipLongest2Collection <Collection1: Collection, Collection2: Collection> {
        @usableFromInline internal var _collection1: Collection1
        @usableFromInline internal var _collection2: Collection2
      
        @inlinable public init (_collection1 collection1: Collection1, _collection2 collection2: Collection2) {
          (_collection1, _collection2) = (collection1, collection2)
        }
      }
      
      extension ZipLongest2Collection: Collection {
        public typealias Element = (Collection1.Element?, Collection2.Element?)
      
        public enum Index: Comparable, CustomStringConvertible {
          case index (Collection1.Index, Collection2.Index)
          case endIndex
      
          @inlinable public static func < (lhs: Index, rhs: Index) -> Bool {
            switch (lhs, rhs) {
              case (.endIndex, _):
                return false
      
              case (_, .endIndex):
                return true
      
              case let (.index(lhsIndex1, lhsIndex2), .index(rhsIndex1, rhsIndex2)):
                return lhsIndex1 < rhsIndex1 && lhsIndex2 < rhsIndex2
            }
          }
      
          @inlinable public var description: String {
            switch (self) {
              case .endIndex:
                return "endIndex"
      
              case let .index(index1, index2):
                return "(\(index1), \(index2))"
            }
          }
        }
      
        @inlinable public var startIndex: Index {
          let index1 = _collection1.startIndex
          let index2 = _collection2.startIndex
      
          return index1 == _collection1.endIndex && index2 == _collection2.endIndex ?
            .endIndex :
            .index(index1, index2)
        }
      
        @inlinable public var endIndex: Index {
          return .endIndex
        }
      
        @inlinable public subscript (position: Index) -> Element {
          switch position {
            case .endIndex:
              preconditionFailure("position must be a valid index of the collection")
      
            case let .index(index1, index2):
              precondition(
                index1 <= _collection1.endIndex && index2 <= _collection2.endIndex,
                "both indices must be lesser than or equal to their end indices"
              )
      
              return (
                index1 == _collection1.endIndex ? .none : .some(_collection1[index1]),
                index2 == _collection2.endIndex ? .none : .some(_collection2[index2])
              )
          }
        }
      
        @inlinable public func index (after index: Index) -> Index {
          switch index {
            case .endIndex:
              preconditionFailure("can't advance beyond endIndex")
      
            case let .index(index1, index2):
              let indexAfterIndex1 = index1 == _collection1.endIndex ?
                _collection1.endIndex :
                _collection1.index(after: index1)
              let indexAfterIndex2 = index2 == _collection2.endIndex ?
                _collection2.endIndex :
                _collection2.index(after: index2)
      
              if indexAfterIndex1 == _collection1.endIndex &&
                 indexAfterIndex2 == _collection2.endIndex {
                return .endIndex
              }
      
              return .index(indexAfterIndex1, indexAfterIndex2)
          }
        }
      }
      

      This:

      print(zipLongest([0, 1, 2], [0]).indices)
      

      Will print a runtime bug (the code still exits with 0):

      DefaultIndices<ZipLongest2Collection<Array<Int>, Array<Int>>>(_elements: Benchmark.ZipLongest2Collection<Swift.Array<Swift.Int>, Swift.Array<Swift.Int>>(_collection1: [0, 1, 2], _collection2: [0])SWIFT RUNTIME BUG: unable to demangle type of field '_startIndex'. mangled type name is '5IndexSlQz'
      2018-08-21 23:24:31.087946+0200 xctest[74142:19397894] SWIFT RUNTIME BUG: unable to demangle type of field '_startIndex'. mangled type name is '5IndexSlQz'
      , _startIndex: ()SWIFT RUNTIME BUG: unable to demangle type of field '_endIndex'. mangled type name is '5IndexSlQz'
      2018-08-21 23:24:31.088083+0200 xctest[74142:19397894] SWIFT RUNTIME BUG: unable to demangle type of field '_endIndex'. mangled type name is '5IndexSlQz'
      , _endIndex: ())
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              dennisvennink Dennis Vennink
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: