5

This code used for building bit pattern from array of bits gives me error in Xcode 9 (works in 8.3.3)

@_specialize(UInt8)
func integerFrom<T: UnsignedInteger>(_ bits: Array<Bit>) -> T {
    var bitPattern: T = 0
    for idx in bits.indices {
        if bits[idx] == Bit.one {
            let bit = T(UIntMax(1) << UIntMax(idx))
            bitPattern = bitPattern | bit
        }
    }
    return bitPattern
}

Error

Unknown parameter UInt8 in '_specialize attribute'

Any leads/suggestion on this?

Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
  • @GoJava The expected behavior of function is already given in comment above the function ("build bit pattern from array of bits"). Thanks for the tip though, I will make it more explicit. – Sahil Kapoor Jun 14 '17 at 07:13
  • Sorry I did not see that(comment removed). Thank you for editing :) –  Jun 14 '17 at 07:14
  • 1
    what is the reason for @_specialize attribute in your code? @_specialize currently acts as a hint to the optimizer ... do you really need this here? if you are sure that you need it, use @_specialize(where T == UInt8) for swift 3.2 – user3441734 Aug 12 '17 at 11:10
  • I recognize this code. You can either remove private specialization attribute or update to Swift 4 syntax with `@_specialize(where T == UInt8)` – Marcin Sep 20 '17 at 12:47

1 Answers1

10

You just need to include a where clause in the specialize definition like this

@_specialize(where T == UInt8)
Fran Martin
  • 2,369
  • 22
  • 19