@@ -76,6 +76,14 @@ final class RemoveRedundantParenthesesTest: XCTestCase {
7676 // `let x = (a + b)` removes parens because InitializerClauseSyntax context
7777 try assertParenRemoval ( " let x = (a + b) " , expected: " let x = a + b " )
7878 try assertParenRemoval ( " let x = ((1)) " , expected: " let x = 1 " )
79+
80+ // `if let` and `guard let` initializers also remove parentheses
81+ try assertParenRemoval ( " if let x = (a + b) {} " , expected: " if let x = a + b {} " )
82+ try assertParenRemoval ( " if var x = (a + b) {} " , expected: " if var x = a + b {} " )
83+ try assertParenRemoval ( " guard let x = (a + b) else {} " , expected: " guard let x = a + b else {} " )
84+
85+ // `try f()` is not a "simple expression", but in an initializer clause the parentheses are still redundant.
86+ try assertParenRemoval ( " let x = (try f()) " , expected: " let x = try f() " )
7987 }
8088
8189 func testPreservesParenthesesInConditions( ) throws {
@@ -91,6 +99,10 @@ final class RemoveRedundantParenthesesTest: XCTestCase {
9199 try assertParenRemoval ( " if (#macro { true }) == false {} " , expected: " if (#macro { true }) == false {} " )
92100 // Subscripts with trailing closures
93101 try assertParenRemoval ( " if (array[0] { true }) == false {} " , expected: " if (array[0] { true }) == false {} " )
102+
103+ // Complex trailing closures in conditions
104+ try assertParenRemoval ( " if (call { true }) == false {} " , expected: " if (call { true }) == false {} " )
105+ try assertParenRemoval ( " if let x: () -> Bool = ({ true }) {} " , expected: " if let x: () -> Bool = ({ true }) {} " )
94106 }
95107
96108 func testPreservesParenthesesForMetatypes( ) throws {
0 commit comments