Skip to content

Add initializer to LabeledExprSyntax that automatically adds a colon if the label exists #1984

Open
@ahoppen

Description

@ahoppen

Currently, if you do the following

let node = EnumCaseParameterSyntax(firstName: "label", type: TypeSyntax("MyType"))
print(node.formatted())

you get label MyType, which is surprising because the colon is missing and you would expect the colon to be present if there is a first name of the enum case parameter.

To fix this, we should add a hand-written initializer of EnumCaseParameterSyntax, which takes a non-optional firstName and automatically adds a colon, because it knows that the firstName exists. The above call would pick that overload and thus add a colon.

And the same strategy can also be applied

  • to other nodes that have an optional colon
  • ClosureCaptureSyntax.equal
  • to automatically add parentheses for the following nodes if arguments are present
    • AttributeSyntax
    • MacroExpansionDeclSyntax
    • ClosureCaptureModifierSyntax
    • FunctionCallExprSyntax
    • FreestandingMacroExpansionSyntax

rdar://107794232

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions