Skip to content

Don't remove leading and trailing parentheses for closure types in type signature disambiguation #1231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

d-ronnqvist
Copy link
Contributor

@d-ronnqvist d-ronnqvist commented Jun 3, 2025

Bug/issue #, if applicable: rdar://151311221

Summary

This fixes an issue where DocC would remove leading and trailing parentheses from certain closure types that return an empty tuple in Swift (as opposed to Void). This resulted in unexpected disambiguation suggestions that didn't actually work when applied to the ambiguous link.

Dependencies

None.

Testing

  • Define some overloads where one of the parameters is a closure that returns (). For example:

    public func doSomething(with closure: (Int) -> Int) -> Int { 0 }
    public func doSomething(with closure: (Bool) -> ()) -> Int { 0 }
    
  • Write an ambiguous link to these overloads:

    /// ``doSomething(with:)``
    public enum Something {}
    
  • The suggestions for what disambiguation to add to should suggest -((Bool)->()) instead of -(Bool)->() to indicate that this is a single closure parameter and not a Bool parameter and a separate Void return value (in this example the function doesn't return Void/()).

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • [ ] Updated documentation if necessary

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@patshaughnessy patshaughnessy left a comment

Choose a reason for hiding this comment

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

Looks good and I was able to verify the (very subtle) fix. Maybe update a comment if you have time.

# Conflicts:
#	Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift
@d-ronnqvist d-ronnqvist force-pushed the fix-closure-parameter-disambiguation-suggestion branch from 496f229 to 798c6ee Compare June 17, 2025 09:30
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist merged commit cd4c34c into swiftlang:main Jun 17, 2025
2 checks passed
d-ronnqvist added a commit to d-ronnqvist/swift-docc that referenced this pull request Jun 18, 2025
…pe signature disambiguation (swiftlang#1231)

* Fix issue where suggested link disambiguation removed leading and trailing parentheses for some closure types

rdar://151311221

* Minor unrelated correction of whitespace in symbol declaration test data

* Include more information in test failure messages about unknown disambiguation
@d-ronnqvist d-ronnqvist deleted the fix-closure-parameter-disambiguation-suggestion branch June 18, 2025 12:47
d-ronnqvist added a commit that referenced this pull request Jun 18, 2025
…pe signature disambiguation (#1231) (#1243)

* Fix issue where suggested link disambiguation removed leading and trailing parentheses for some closure types

rdar://151311221

* Minor unrelated correction of whitespace in symbol declaration test data

* Include more information in test failure messages about unknown disambiguation
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.

2 participants