[SR-12061] Swift "The Swift Programming Language" docs misleading on subscript #54497
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
documentation
Additional Detail from JIRA
md5: b1de181b9e83f8a53f5dda1a33d1d076
Issue Description:
tldr; The section of custom subscripts should in some fashion discuss the different between a parameter-only subscript and one with a label-parameter.
The subscript section of the manual has numerous examples and even has a "Subscript Syntax" section, where you can see this:
Other text says the syntax is similar to Swift method syntax. Fine. But then I scratch my head - in a method, to call the above, I'd have to use a "index" label, say:
Ah, so I get it - there is an implied "_" label in the above declaration - under the hood its:
subscript(_ index: Int) -> Int
Then, the other day, I see an example of a custom subscript method similar to this:
Now my head is really spinning! The "under the hood" declaration of the above cannot possible be:
So then I think I'm getting it. If there is just a single label (the parameter name), then the "_" is implied. If there are two "labels" (a label and parameter), then the label works just like in a method descriptions.
PS: I did look at the "Language Reference", but it doesn't appear that this is covered (although it well may be, that isn't an easy read)
The text was updated successfully, but these errors were encountered: