<!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. Consider the following code:<br></div>
<div> </div>
<div>var foo = Foo()<br></div>
<div>do {<br></div>
<div> XCTAssertEqual(try foo.doSomething(), 42)<br></div>
<div>} catch {<br></div>
<div> XCTAssertEqual(foo.success, false)<br></div>
<div>}<br></div>
<div> </div>
<div>Adding ‘throws’ to the autoclosures will:<br></div>
<div> </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> </div>
<div>Did you actually test this code? Because this code <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> </div>
<div>error: call can throw, but it is executed in a non-throwing autoclosure<br></div>
<div> </div>
<blockquote type="cite"><div dir="ltr"><div><div>(2) hijacks ‘try’ and defeats its purpose — being able to understand the control flow. Developers know that if they see a ‘try’, it should match with either a do-catch, or be used in a throwing function. Adding this API makes the code misleading.<br></div>
</div>
</div>
</blockquote><div> </div>
<div>Or use it in a throwing @autoclosure.</div>
<div> </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. But adding error handling to regular assertion functions has the potential to create misleading code.<br></div>
<div> </div>
<div>Changing the way control flow works breaks one of the basic language features — substitutability:<br></div>
<div> </div>
<div>let bar1 = try bar()<br></div>
<div>foo(bar1)<br></div>
<div> </div>
<div>should be equivalent to:<br></div>
<div> </div>
<div>foo(try bar())<br></div>
</div>
</div>
</blockquote><div> </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> </div>
<div>-Kevin Ballard</div>
</body>
</html>