Skip to content

Instantly share code, notes, and snippets.

@amosr
Created January 28, 2016 07:24
Show Gist options
  • Save amosr/f47c94498360fea151d0 to your computer and use it in GitHub Desktop.
Save amosr/f47c94498360fea151d0 to your computer and use it in GitHub Desktop.
cast :: UnsafeMutablePointer<T> -> UnsafeMutablePointer<U> in Swift?
13> let y : UnsafeMutablePointer<UInt8> = unsafeDowncast(malloc(50))
repl.swift:13:39: error: generic parameter 'T' could not be inferred
let y : UnsafeMutablePointer<UInt8> = unsafeDowncast(malloc(50))
^
Swift.unsafeDowncast:12:13: note: in call to function 'unsafeDowncast'
public func unsafeDowncast<T : AnyObject>(x: AnyObject) -> T
^
13> let y : UnsafeMutablePointer<UInt8> = unsafeDowncast<UnsafeMutablePointer<UInt8>>(malloc(50))
repl.swift:13:39: error: cannot explicitly specialize a generic function
let y : UnsafeMutablePointer<UInt8> = unsafeDowncast<UnsafeMutablePointer<UInt8>>(malloc(50))
^
repl.swift:13:53: note: while parsing this '<' as a type parameter bracket
let y : UnsafeMutablePointer<UInt8> = unsafeDowncast<UnsafeMutablePointer<UInt8>>(malloc(50))
16> let y : UnsafeMutablePointer<UInt8> = malloc(50) as UnsafeMutablePointer<UInt8>
repl.swift:16:39: error: cannot convert value of type 'UnsafeMutablePointer<Void>' (aka 'UnsafeMutablePointer<()>') to type 'UnsafeMutablePointer<UInt8>' in coercion
let y : UnsafeMutablePointer<UInt8> = malloc(50) as UnsafeMutablePointer<UInt8>
^~~~~~~~~~
20> let y : UnsafeMutablePointer<UInt8> = malloc(50) as! UnsafeMutablePointer<UInt8>
y: UnsafeMutablePointer<UInt8> = <extracting data from value failed>
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment