You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SR-15727] swift-format thinks parens used to disambiguate closures in if conditions are not necessary turning compiling code into not compiling code
#298
Closed
weissi opened this issue
Jan 13, 2022
· 2 comments
$ swift /tmp/t1.swift
/tmp/t1.swift:1:1: error: missing condition in an 'if' statement
if { _isDebugAssertConfiguration() }() { print("debug") }
^~~~
/tmp/t1.swift:1:37: error: consecutive statements on a line must be separated by ';'
if { _isDebugAssertConfiguration() }() { print("debug") }
^
;
/tmp/t1.swift:1:39: error: consecutive statements on a line must be separated by ';'
if { _isDebugAssertConfiguration() }() { print("debug") }
^
;
/tmp/t1.swift:1:40: error: top-level statement cannot begin with a closure expression
if { _isDebugAssertConfiguration() }() { print("debug") }
^
/tmp/t1.swift:1:6: warning: result of call to '_isDebugAssertConfiguration()' is unused
if { _isDebugAssertConfiguration() }() { print("debug") }
^ ~~
/tmp/t1.swift:1:40: error: closure expression is unused
if { _isDebugAssertConfiguration() }() { print("debug") }
^
/tmp/t1.swift:1:40: note: did you mean to use a 'do' statement?
if { _isDebugAssertConfiguration() }() { print("debug") }
^
do
The text was updated successfully, but these errors were encountered:
…n conditions (swiftlang#298)
A bit of a mouthfull to fit into a reasonably sized commit message. The
NoParensAroundConditions rule removed parens around immediately called closures
and in doing so introduced ambiguities into code that was correct to begin with.
Environment
all swift-formats incl 5.6 and main
Additional Detail from JIRA
md5: 3eeb9bd3515a4c45827dcf5f69f24625
Issue Description:
Description
The following Swift program compiles & works just fine
please note that the parens around {{ {_isDebugAssertConfiguration() {} }() }} are NOT optional.
When formatted with
swift-format
however, it gets turned into this programwhich doesn't actually compile... The problem is that now, the curly braces for the closure / the if body are ambiguous to the parser...
Details
Original program works:
after formatting however:
it doesn't compile anymore
The text was updated successfully, but these errors were encountered: