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
It is likely that a future version of Swift will support an async keyword where we would expect throws to be. That means we can anticipate that, in the future, current Swift compilers will accidentally be fed code using the async keyword in this way.
<stdin>:1:11: error: consecutive statements on a line must be separated by ';'
func fn1() async {}
^
;
<stdin>:2:11: error: consecutive statements on a line must be separated by ';'
func fn2() async -> Void {}
^
;
<stdin>:3:11: error: consecutive statements on a line must be separated by ';'
func fn3() async throws {}
^
;
<stdin>:3:18: error: 'throws' may only occur before '->'
func fn3() async throws {}
^
<stdin>:3:25: error: top-level statement cannot begin with a closure expression
func fn3() async throws {}
^
<stdin>:4:11: error: consecutive statements on a line must be separated by ';'
func fn4() async throws -> Void {}
^
;
<stdin>:5:18: error: consecutive statements on a line must be separated by ';'
func fn5<T>(_: T) async where T: AnyObject {}
^
;
<stdin>:5:24: error: consecutive statements on a line must be separated by ';'
func fn5<T>(_: T) async where T: AnyObject {}
^
;
<stdin>:5:25: error: expected expression
func fn5<T>(_: T) async where T: AnyObject {}
^
<stdin>:5:44: error: top-level statement cannot begin with a closure expression
func fn5<T>(_: T) async where T: AnyObject {}
^
<stdin>:1:6: error: expected '{' in body of function declaration
func fn1() async {}
^
<stdin>:1:12: error: cannot find 'async' in scope
func fn1() async {}
^~~~~
<stdin>:2:6: error: expected '{' in body of function declaration
func fn2() async -> Void {}
^
<stdin>:2:12: error: cannot find 'async' in scope
func fn2() async -> Void {}
^~~~~
<stdin>:2:12: error: expected type before '->'
func fn2() async -> Void {}
^
<stdin>:2:21: error: expected type after '->'
func fn2() async -> Void {}
^
<stdin>:3:6: error: expected '{' in body of function declaration
func fn3() async throws {}
^
<stdin>:3:25: error: closure expression is unused
func fn3() async throws {}
^
<stdin>:3:25: note: did you mean to use a 'do' statement?
func fn3() async throws {}
^
do
<stdin>:4:6: error: expected '{' in body of function declaration
func fn4() async throws -> Void {}
^
<stdin>:4:12: error: cannot find 'async' in scope
func fn4() async throws -> Void {}
^~~~~
<stdin>:4:12: error: expected type before '->'
func fn4() async throws -> Void {}
^
<stdin>:4:28: error: expected type after '->'
func fn4() async throws -> Void {}
^
<stdin>:5:6: error: expected '{' in body of function declaration
func fn5<T>(_: T) async where T: AnyObject {}
^
<stdin>:5:19: error: cannot find 'async' in scope
func fn5<T>(_: T) async where T: AnyObject {}
^~~~~
<stdin>:5:44: error: closure expression is unused
func fn5<T>(_: T) async where T: AnyObject {}
^
<stdin>:5:44: note: did you mean to use a 'do' statement?
func fn5<T>(_: T) async where T: AnyObject {}
^
do
We could tailor a diagnostic specifically for async, but honestly, it might be better to design a more general recovery behavior that's more intelligent than the current one. For instance, the parser might look past an unknown identifier and, if it sees that the next token is throws, rethrows, ->, {, or where, diagnose the unknown identifier and resume parsing normally.
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: 8baa712ca988a4f748590accc728d8ce
Issue Description:
It is likely that a future version of Swift will support an
async
keyword where we would expectthrows
to be. That means we can anticipate that, in the future, current Swift compilers will accidentally be fed code using theasync
keyword in this way.If you feed code like that to Swift 5.3:
You get a spew of 27 terrible diagnostics:
We could tailor a diagnostic specifically for
async
, but honestly, it might be better to design a more general recovery behavior that's more intelligent than the current one. For instance, the parser might look past an unknown identifier and, if it sees that the next token isthrows
,rethrows
,->
, {, orwhere
, diagnose the unknown identifier and resume parsing normally.The text was updated successfully, but these errors were encountered: