Skip to content

Conversation

@Padmashree06
Copy link

This PR adds documentation comments for the following Syntax nodes:

  • SwitchCaseLabelSyntax
  • SwitchDefaultLabelSyntax
  • SwitchCaseSyntax
  • ThrowStmtSyntax
  • ReturnClauseSyntax
  • ReturnStmtSyntax
  • TypeInitializerClauseSyntax
  • TypeAnnotationSyntax

The documentation follows the format used in #1527 and includes
brief explanations and examples where applicable.

This contributes to issue #1528.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks for adding the documentation @Padmashree06. I added a few comments below.

base: .syntax,
nameForDiagnostics: nil,
documentation: """
A clause that specifies the underlying type of a type declaration.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
A clause that specifies the underlying type of a type declaration.
A clause that specifies the underlying type of a `typealias` or `associatedtype` declaration.

```

```swift
func greet(name: String) {}
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 497 to 507
A statement that exits a function or closure and optionally returns a value.

Written as:
```swift
return
```

```swift
return <expr>
```
""",
Copy link
Member

Choose a reason for hiding this comment

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

The indentation seems a little off to me here, both within the code blocks and overall.

Same below

name: "expression",
kind: .node(kind: .expr)
kind: .node(kind: .expr),
nameForDiagnostics: "error"
Copy link
Member

Choose a reason for hiding this comment

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

Did you intentionally change the name for diagnostics here?

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Thank you for working on this issue!
I left a few comment regarding the general direction of this. I'd like to hear the opinions from @ahoppen about them as well.

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.

Comment on lines 2177 to 2180
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

-> <type>
```

### 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.

@Padmashree06
Copy link
Author

The requested changes have been addressed, and the test suite passes without issues.

@Padmashree06
Copy link
Author

@ahoppen @rintaro
I have made the necessary changes.
Could you please review it.
Thank you for your time.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you

@ahoppen ahoppen marked this pull request as draft February 3, 2026 10:31
@ahoppen ahoppen marked this pull request as ready for review February 3, 2026 10:31
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.

3 participants