0

We have a special logging function that represents a particular type of crash, and as such, internally it calls fatalError. However, unlike fatalError, when we use it in a guard statement, it still complains we haven't exited the scope of the guard.

I checked the source code and fatalError returns -> Never so I tried that, but that didn't work either. I also didn't see any attributes applied to it that may be telling the compiler 'this is the end of the road'.

So is it possible to have your own fatalError-like method?

func myFatalError(memberName:String = #function) -> Never {
    let message = "Failed in \(memberName)" 
    NSLog(message)
    fatalError(message)
}
Hamish
  • 78,605
  • 19
  • 187
  • 280
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286

1 Answers1

0

As pointed out by others, the issue was something on my machine specifically. The following (returning 'Never') works as expected.

func myFatalError() -> Never {
    print("Doing something fatal")
}
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286