Skip to content

Allow trailing commas in macro role attribute arguments#3361

Open
nenadvulic wants to merge 1 commit into
swiftlang:mainfrom
nenadvulic:allow-trailing-comma-macro-role
Open

Allow trailing commas in macro role attribute arguments#3361
nenadvulic wants to merge 1 commit into
swiftlang:mainfrom
nenadvulic:allow-trailing-comma-macro-role

Conversation

@nenadvulic

Copy link
Copy Markdown
Contributor

Fixes #3306.

parseMacroRoleArguments parsed its argument list with allowTrailingComma: false, even though the equivalent custom-attribute path already uses allowTrailingComma: true. As the issue notes, SE-0439 generalized trailing commas to comma-separated lists like these, and to the user (and in the AST) macro role arguments are a regular LabeledExprListSyntax. The false looks like an oversight from when trailing-comma support was rolled out (enabled for custom attributes but not for macro role attributes).

Change

  • Sources/SwiftParser/Attributes.swift: parseMacroRoleArguments now passes allowTrailingComma: true, matching the custom-attribute argument path.

Test

  • Tests/SwiftParserTest/TrailingCommaTests.swift: added testMacroRoleAttributes, mirroring the existing testCustomAttributes, covering @attached(...) and @freestanding(...) with a trailing comma.

Verified the test fails before the change (expected value in attribute) and passes after. TrailingCommaTests, AttributeTests, and DeclarationTests all pass with no regressions.

parseMacroRoleArguments passed allowTrailingComma: false, unlike the
custom-attribute argument path. SE-0439 generalized trailing commas to
these comma-separated lists, so a trailing comma in e.g.
@attached(member, names: named(foo),) should parse cleanly.

Fixes swiftlang#3306.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parseMacroRoleArguments should allow trailing commas

1 participant