What is Never? Where do you see it?
Predict first
Does this compile?
func value() -> Int {
fatalError("todo")
}
- Yes
- No — missing return
Predict first
Does this compile without try?
let r: Result<Int, Never> = .success(1)
let v = r.get()
- Yes
- No — get() throws
Predict first
Does this compile?
func stop() -> Never {
return
}
- Yes
- No
Mental model. Never is the empty set — a box with no possible contents, so any code path that “returns” one can never actually continue.
Never is an uninhabited type: it has no values, so a function returning Never can never return normally. It signals “this path does not continue” — fatalError, a trap, or an infinite loop.
It is used as a generic placeholder meaning “cannot fail”: Result<T, Never>, a Combine publisher with Failure == Never, or a closure that always traps. The compiler treats a Never return as a noreturn path, which is why fatalError() satisfies a function that must return a value.
fatalError returns Never, so the compiler knows the path ends there. No return is needed.
get() is throws(Failure). With Failure == Never it cannot throw, so Swift 6 does not ask for try.
There is no value of type Never to return. The only legal bodies trap or loop forever.
Common traps
- “
Neveris justVoid.”Voidhas exactly one value,().Neverhas zero — that difference is why the compiler can reason about unreachable code.
They might follow up with
- Why does
Result<T, Never>exist? So an API that cannot fail can still use the same type, andget()becomes non-throwing. - Can you write
func f() -> Neverthat returns? No — there is no value you could return. The only legal implementations trap or never terminate.