By the way, return Never used to be called @noreturn, so you weren't far off!<br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 24, 2017 at 02:22 Rien via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Excellent!<br class="gmail_msg">
<br class="gmail_msg">
Love this list ;-)<br class="gmail_msg">
<br class="gmail_msg">
Regards,<br class="gmail_msg">
Rien<br class="gmail_msg">
<br class="gmail_msg">
Site: <a href="http://balancingrock.nl" rel="noreferrer" class="gmail_msg" target="_blank">http://balancingrock.nl</a><br class="gmail_msg">
Blog: <a href="http://swiftrien.blogspot.com" rel="noreferrer" class="gmail_msg" target="_blank">http://swiftrien.blogspot.com</a><br class="gmail_msg">
Github: <a href="http://github.com/Balancingrock" rel="noreferrer" class="gmail_msg" target="_blank">http://github.com/Balancingrock</a><br class="gmail_msg">
Project: <a href="http://swiftfire.nl" rel="noreferrer" class="gmail_msg" target="_blank">http://swiftfire.nl</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
> On 24 Mar 2017, at 10:12, Philip Erickson <<a href="mailto:philiperickson@gmail.com" class="gmail_msg" target="_blank">philiperickson@gmail.com</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> I believe returning Never does what you want, e.g.<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> import Foundation<br class="gmail_msg">
><br class="gmail_msg">
> func findReasonAndTerminate() -> Never<br class="gmail_msg">
> {<br class="gmail_msg">
> let reason: String = findReason()<br class="gmail_msg">
> fatalError(reason)<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> func findReason() -> String<br class="gmail_msg">
> {<br class="gmail_msg">
> return "some reason"<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> func buildData() -> Data?<br class="gmail_msg">
> {<br class="gmail_msg">
> return nil<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> guard let data = buildData() else { findReasonAndTerminate() }<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> On Fri, Mar 24, 2017 at 3:02 AM, Rien via swift-users <<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a>> wrote:<br class="gmail_msg">
> Is there any way to mark a function as “no return”?<br class="gmail_msg">
><br class="gmail_msg">
> Reason: The compiler generates an error when the else block from a guard does not terminate the execution by either a return or a fatalError. I want to call out to a function and raise the fatalError in that function.<br class="gmail_msg">
><br class="gmail_msg">
> func findReasonAndTerminate() {<br class="gmail_msg">
> let reason: String = ….<br class="gmail_msg">
> fatalError(reason)<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> main.swift:<br class="gmail_msg">
><br class="gmail_msg">
> guard let data = buildData() else { findReasonAndTerminate() }<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> Currently the work around is to add another fatalError like this:<br class="gmail_msg">
><br class="gmail_msg">
> guard let data = buildData() else { findReasonAndTerminate(); fatalError }<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> but it would be nice to have some attribute like @noReturn:<br class="gmail_msg">
><br class="gmail_msg">
> @noReturn<br class="gmail_msg">
> func findReasonAndTerminate() { … }<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> Regards,<br class="gmail_msg">
> Rien<br class="gmail_msg">
><br class="gmail_msg">
> Site: <a href="http://balancingrock.nl" rel="noreferrer" class="gmail_msg" target="_blank">http://balancingrock.nl</a><br class="gmail_msg">
> Blog: <a href="http://swiftrien.blogspot.com" rel="noreferrer" class="gmail_msg" target="_blank">http://swiftrien.blogspot.com</a><br class="gmail_msg">
> Github: <a href="http://github.com/Balancingrock" rel="noreferrer" class="gmail_msg" target="_blank">http://github.com/Balancingrock</a><br class="gmail_msg">
> Project: <a href="http://swiftfire.nl" rel="noreferrer" class="gmail_msg" target="_blank">http://swiftfire.nl</a><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> swift-users mailing list<br class="gmail_msg">
> <a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a><br class="gmail_msg">
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="gmail_msg">
><br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
swift-users mailing list<br class="gmail_msg">
<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="gmail_msg">
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div>