Skip to content

Instantly share code, notes, and snippets.

@ezura
Created October 6, 2017 06:15
Show Gist options
  • Save ezura/c0c8cf26ebbac0242e82385de2182845 to your computer and use it in GitHub Desktop.
Save ezura/c0c8cf26ebbac0242e82385de2182845 to your computer and use it in GitHub Desktop.
Never の function 呼び出すの、Swift だとこんな感じかなぁ…。 とりあえず、unsafeBitCast で Never と memory layout が同じ型 (Void) にキャストすると実行までできた( 'ω') #CodePiece
// goal: call `(Never instance).foo()`
extension Never {
func foo() { print("exec") }
}
unsafeBitCast((), to: Never.self).foo() // print "exec"
(nil as Never?)?.foo() // ()?
fatalError().foo() // runtime error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment