8000 Trailing comma not allowed in @available annotation despite SE-0439 · Issue #81475 · swiftlang/swift · GitHub
[go: up one dir, main page]

Skip to content

Trailing comma not allowed in @available annotation despite SE-0439 #81475

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

Open
calda opened this issue May 13, 2025 · 5 comments
Open

Trailing comma not allowed in @available annotation despite SE-0439 #81475

calda opened this issue May 13, 2025 · 5 comments
Labels
attributes Feature: Declaration and type attributes bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself parser Area → compiler: The legacy C++ parser swift 6.2 unexpected error Bug: Unexpected error

Comments

@calda
Copy link
Contributor
calda commented May 13, 2025

Description

Trailing commas are unexpectedly not allowed in @available annotations, despite annotations being mentioned as a supported use case in SE-0439.

@available(
    *,
    deprecated,
    renamed: "bar", // unexpectedly not allowed
)
func foo() { }

Reproduction

Compile the above code using Swift 6.1+: https://swiftfiddle.com/oiaoenmyxbcajdqv4m522kji3q

Expected behavior

It should compile but doesn't

Environment

Swift version 6.2-dev (LLVM a3e32cdaae72f3d, Swift fa86097)

Additional information

No response

@calda calda added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 13, 2025
@calda
Copy link
Contributor Author
calda commented May 13, 2025

Issue also applies to any built-in attribute with parens, like @backDeployed, @attached, @freestanding, and @objc(...):

@backDeployed(
  before: iOS 17 // trailing comma not allowed
)
public func foo() {}

@freestanding(
  declaration,
  names: named(CodingKeys) // trailing comma not allowed
)
macro FreestandingMacro() = #externalMacro(module: "Macros", type: "")

@attached(
  extension,
  names: arbitrary // trailing comma not allowed
)
macro AttachedMacro() = #externalMacro(module: "Macros", type: "")

and I suspect also all of the underscored built-in attributes, e.g.:

@_originallyDefinedIn(
    module: "Foo",
    macOS 10.0  // trailing comma not allowed
)
struct Bar {}

@calda
Copy link
Contributor Author
calda commented May 13, 2025

fyi @mateusrodriguesxyz

@calda
Copy link
Contributor Author
calda commented May 19, 2025

Fixed in #81612

@calda
Copy link
Contributor Author
calda commented May 19, 2025

This appears to be intentional: #81612 (comment)

@xwu
Copy link
Collaborator
xwu commented May 20, 2025

Yeah, there's a bit of underspecification here with the proposal.

The bottom line is that we resolved to allow trailing commas where we have purely a comma-separated list within symmetric delimiters and we disallow trailing commas where commas aren't ever permitted within symmetric delimiters (for example: [Int,] in type position—there is an extant bug where we accept this in some contexts which the steering group felt was not reason for official adoption).

As you've noted, attributes can have custom parsing for their arguments, and during this proposal process no attempt was made to sort out which should or should not be considered purely comma-separated lists that support trailing commas—as this work was never done we have to consider it not part of the approved proposal.

@AnthonyLatsis AnthonyLatsis added parser Area → compiler: The legacy C++ parser compiler The Swift compiler itself attributes Feature: Declaration and type attributes unexpected error Bug: Unexpected error swift 6.2 and removed triage needed This issue needs more specific labels labels May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attributes Feature: Declaration and type attributes bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself parser Area → compiler: The legacy C++ parser swift 6.2 unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

3 participants
0