Skip to content
32 changes: 32 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,24 @@ public let DECL_NODES: [Node] = [
kind: .returnClause,
base: .syntax,
nameForDiagnostics: nil,
documentation: """
A clause that specifies the return type of a function or closure.
Copy link
Member

@rintaro rintaro Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually function, subscript, type, or closure.

// function
func f() -> Int { }
// subscript
subscript(I: Int) -> Int {}
// type
let a: () -> Int = { 1 }
// closure
_ = { () -> Int in 1 }

But I'm not sure we should list everything here. This information is automatically rendered as "Contained in" section.
So maybe A clause that specifies the return type is enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposal would be A clause that specifies the return type, typically of a function or subscript. That leaves room for the slightly more edge cases in the Contained In section, while still giving you an idea of what this is about.


Written as:
```swift
-> <type>
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technically a duplicated information with ### Children section in the rendered doc-comments. Although this simplified code might be nice to read, my personal preference is not to have this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, I don’t have a strong opinion here either way


### Examples
Copy link
Member

@rintaro rintaro Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure we should write a section (###) here. It's the same header level as other generated sections (i.e. ### Children and ### Contained in), If we want another section for "examples", we might need another property on Node.

But I think something like this would be enough.

A clause that specifies the return type.

For example, the `-> Int` part in
```swift
func foo() throws -> Int { ... }
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a lot of precedence for ### Examples sections in the documentation, just search for that string in CodeGeneration. So, I vote to keep it.

I’m not opposed to moving the examples into a different property of Node but I think that should be a different PR.


```swift
func f() -> Int { }
```

```swift
let g: () -> String = { "hello" }
```
""",
children: [
Child(
name: "arrow",
Expand Down Expand Up @@ -2437,6 +2455,20 @@ public let DECL_NODES: [Node] = [
kind: .typeInitializerClause,
base: .syntax,
nameForDiagnostics: nil,
documentation: """
A clause that specifies the underlying type of `typealias` or `associatedtype` declaration.

Written as:
```swift
= <type>
```

### Examples

```swift
typealias MyInt = Int
```
""",
children: [
Child(
name: "equal",
Expand Down
46 changes: 46 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,24 @@ public let EXPR_NODES: [Node] = [
kind: .switchCaseLabel,
base: .syntax,
nameForDiagnostics: nil,
documentation: """
A label that introduces one or more cases in a switch statement.

Written as:
```swift
case <items>:
```

### Examples

```swift
case 1:
```

```swift
case 1, 2, 3:
```
""",
children: [
Child(
name: "caseKeyword",
Expand Down Expand Up @@ -1930,6 +1948,25 @@ public let EXPR_NODES: [Node] = [
kind: .switchCase,
base: .syntax,
nameForDiagnostics: "switch case",
documentation: """
A single case within a `switch` statement.

A switch case consists of a label (`case` or `default`),
an optional `@unknown` attribute, and the statements
that are executed when the case is matched.

### Examples

```swift
case 1:
print("one")
```

```swift
default:
print("other")
```
""",
parserFunction: "parseSwitchCase",
traits: ["WithStatements"],
children: [
Expand Down Expand Up @@ -1969,6 +2006,15 @@ public let EXPR_NODES: [Node] = [
kind: .switchDefaultLabel,
base: .syntax,
nameForDiagnostics: nil,
documentation: """
The default label is executed when none of the `case` patterns
match the value being switched over.

Written as:
```swift
default:
```
""",
children: [
Child(
name: "defaultKeyword",
Expand Down
17 changes: 17 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ public let PATTERN_NODES: [Node] = [
kind: .typeAnnotation,
base: .syntax,
nameForDiagnostics: "type annotation",
documentation: """
A type annotation that explicitly specifies the type of a value or pattern.

Written as a colon followed by a type:
```swift
<pattern>: <type>
```

### Examples

```swift
let count: Int
```
```swift
let point: (x: Int, y: Int)
```
""",
children: [
Child(
name: "colon",
Expand Down
21 changes: 21 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,18 @@ public let STMT_NODES: [Node] = [
kind: .returnStmt,
base: .stmt,
nameForDiagnostics: "'return' statement",
documentation: """
A statement that exits a function or closure and optionally returns a value.

Written as:
```swift
return
```

```swift
return <expr>
```
""",
children: [
Child(
name: "returnKeyword",
Expand All @@ -510,6 +522,15 @@ public let STMT_NODES: [Node] = [
kind: .throwStmt,
base: .stmt,
nameForDiagnostics: "'throw' statement",
documentation: """
A statement that throws an error.

Written as:

```swift
throw <expr>
```
""",
children: [
Child(
name: "throwKeyword",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxCollections.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesQRS.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.