swiftlang / swiftlang/swift-syntax

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

Open
#1,984 17 comments 0 reactions 1 assignee Claimed by @natikgadzhi View on GitHub
enhancement good first issue
Dominant language
Swift
Stars
3.7k
Forks
553
Avg merge
5d 13h
Merged PRs (30d)
16

Description

Currently, if you do the following

```swift
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.