-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Disallow spaces between @
, attribute name and (
in Swift 6
#71237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow spaces between @
, attribute name and (
in Swift 6
#71237
Conversation
@
, attribute name and (
.@
, attribute name and (
in Swift 6
Oh, does this fix the issue with writing let closure = { @MainActor (a, b) in
print(a, b)
} |
It doesn’t actually fix the issue because there’s no behavior change (for source compatibility reasons). But it will produce a warning in Swift 5 and an error in Swift 6. let closure = { @MainActor (a, b) in // error: extraneous whitespace between attribute name and '('
} My thought was that we should stage this as a diagnostic and then we can change the parsing behavior to unambiguously parse |
8353e68
to
eb350cc
Compare
test/Parse/attribute_spacing.swift
Outdated
@ MainActor // expected-error {{extraneous whitespace between '@' and attribute name}} | ||
class Foo { | ||
func foo(_ x: @ escaping () -> Int) {} // expected-error {{extraneous whitespace between '@' and attribute name}} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth adding tests to cover the warning behavior and the newline case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think adding a dedicated test case for the warning is worth it. See #71238 (comment)
What do you mean by the newline case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by the newline case?
The case where the @
is on the previous line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test case for
let closure = { @MainActor
(a, b) in
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I should have been clearer, I meant e.g:
@
MainActor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8533073
to
7731b03
Compare
@swift-ci Please smoke test |
This allows us to resolve disambiguities of whether a parenthesis belong to an argument to the attribute or if it is eg. the start of a tuple.
7731b03
to
c6e425a
Compare
@swift-ci Please smoke test |
@
and attribute name in Swift 6 mode@
and the attribute name (or even having them on different lines) is weird and shouldn’t be allowed