<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>On Sun, Jan 10, 2016, at 11:18 AM, Dmitri Gribenko via swift-evolution wrote:0<br></div>
<blockquote type="cite"><div dir="ltr"><div><div>I have significant concerns about doing this.&nbsp; Consider the following code:<br></div>
<div>&nbsp;</div>
<div>var foo = Foo()<br></div>
<div>do {<br></div>
<div>&nbsp; &nbsp; XCTAssertEqual(try foo.doSomething(), 42)<br></div>
<div>} catch {<br></div>
<div>&nbsp; &nbsp; XCTAssertEqual(foo.success, false)<br></div>
<div>}<br></div>
<div>&nbsp;</div>
<div>Adding ‘throws’ to the autoclosures will:<br></div>
<div>&nbsp;</div>
<div>(1) change meaning of existing tests (the example above used to proceed to the catch block in case of errors, and will start failing with this change),<br></div>
</div>
</div>
</blockquote><div>&nbsp;</div>
<div>Did you actually test this code? Because this code&nbsp;<b>does not compile today</b>. You cannot pass a throwing expression to an @autoclosure that takes a non-throwing function. The specific error you get is<br></div>
<div>&nbsp;</div>
<div>error: call can throw, but it is executed in a non-throwing autoclosure<br></div>
<div>&nbsp;</div>
<blockquote type="cite"><div dir="ltr"><div><div>(2) hijacks ‘try’ and defeats its purpose — being able to understand the control flow.&nbsp; Developers know that if they see a ‘try’, it should match with either a do-catch, or be used in a throwing function.&nbsp; Adding this API makes the code misleading.<br></div>
</div>
</div>
</blockquote><div>&nbsp;</div>
<div>Or use it in a throwing @autoclosure.</div>
<div>&nbsp;</div>
<blockquote type="cite"><div dir="ltr"><div><div>Note that although (2) applies to the XCTAssertThrowsError() API, because the name of that API makes it clear it is doing something special with error handling, I’m not concerned about it.&nbsp; But adding error handling to regular assertion functions has the potential to create misleading code.<br></div>
<div>&nbsp;</div>
<div>Changing the way control flow works breaks one of the basic language features — substitutability:<br></div>
<div>&nbsp;</div>
<div>let bar1 = try bar()<br></div>
<div>foo(bar1)<br></div>
<div>&nbsp;</div>
<div>should be equivalent to:<br></div>
<div>&nbsp;</div>
<div>foo(try bar())<br></div>
</div>
</div>
</blockquote><div>&nbsp;</div>
<div>@autoclosure already breaks that. Adding error handling to the @autoclosure doesn't change anything. In fact, breaking that substitutability is basically the whole reason for @autoclosure to exist.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard</div>
</body>
</html>