Created
October 6, 2017 06:15
-
-
Save ezura/c0c8cf26ebbac0242e82385de2182845 to your computer and use it in GitHub Desktop.
Never の function 呼び出すの、Swift だとこんな感じかなぁ…。
とりあえず、unsafeBitCast で Never と memory layout が同じ型 (Void) にキャストすると実行までできた( 'ω') #CodePiece
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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