DocC doesn't handled named subscript parameters correctly

Xcode 14.0.1 running on macOS Monterey 12.6.

I have a class MeetingDirectory that defines two subscript functions:

public subscript(_ date: String) -> ValueOrMessage<Meeting> { ... }
public subscript(_ date: String, visit: CaseID) -> ValueOrMessage<Meeting> { ... }

In my DocC extension file for this class, I want to generate links to the documentation for both subscripts.

Problem 1: I type two backticks and Xcode offers autocompletions for all the class's public functions, including two subscript functions; but the subscript functions are each presented in the autocomplete list as just subscript with no additional information — there is no way to differentiate them.

Problem 2: By trial-and-error, I find that one subscript expands into subscript(_:) and the other one expands into subscript(_:visit:), as I would have expected. So my topics list looks like:

### Getting a Specific Meeting

- ``subscript(_:)``
- ``subscript(_:visit:)``

But when I compile the documentation, the subscript(_:visit:) line gets this warning: “Topic reference 'subscript(_%3Avisit%3A)' couldn't be resolved. No local documentation matches this reference.” and subscript(_:visit:) doesn't show up in the “Getting a Specific Meeting” topic section. Instead, it shows up in the default “Subscripts” section, with the signature

subscript(String, CaseID) -> ValueOrMessage<Meeting>

and if you click on the link, the title on the function documentation page has the signature subscript(_:_:) (although the “Declaration” and “Parameters” sections on the function documentation page are correct).

Problem 3: So I tried writing the symbol reference as subscript(_:_:) instead. Now the documentation compiles without errors, and both subscript functions show up under “Getting a Specific Meeting”, but, as you might expect, it still shows up with the (_:_:) signature.

Honestly, this sounds like a bug to me (well, perhaps a small group of bugs flying in formation). I think Xcode is an innocent bystander here, and that the real problem lies in DocC itself. I had a quick look at the DocC open source bug database and didn’t spot anything relevant. My advice:

  1. See if you can reproduce the problem using the open source DocC.

  2. If you can, file a bug there.

Alternatively, you should feel free to file a bug against Xcode, although you’ll be able to see more status on your bug if you go the open source route.

Regardless, please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It looks like this was a user error on my apart, abetted by an apparent bug in symbol-reference autocompletion.

I had completely forgotten that the parameter naming rules for subscripts are different than for functions: subscript parameters don't take a label in the call unless you explicitly specify both a label and a local name in the declaration. So the type of the subscript declared

public subscript(_ date: String, visit: CaseID) -> ValueOrMessage<Meeting> { ... }

really is subscript(_:_:). not subscript(_:visit:). That explains why explicitly using the (::) worked. But it doesn't explain why the editor autocompletion wanted to give me (_:visit:). Anyway, changing the code declaration to

public subscript(_ date: String, visit visit: CaseID) -> ValueOrMessage<Meeting> { ... }

made the subscript work the way I expected, and made autocompletion work, too.

BUT ...

Roughly the same problem shows up with operator functions, and in this case, it looks like it may really be a DocC bug.

Consider

        public static func ==(_ lhs: Meeting.Item, _ rhs: Meeting.Item) -> Bool {...}
        public static func <(_ lhs: Meeting.Item, _ rhs: Meeting.Item) -> Bool {...}

and, in the documentation extension file,

- ``<(_:_:)``
- ``==(_:_:)``

The equality declaration reference works as expected, and the apparently identical less-than declaration fails. In the Swift source, I get the diagnostic “Topic reference '%3C(%3A%3A)' couldn't be resolved. No local documentation matches this reference.” and in the documentation page the equality function shows up in my Ordering section, but the less-than function shows up in the auto-created Operators section.

DocC doesn't handled named subscript parameters correctly
 
 
Q