Skip to content
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

[SR-12061] Swift "The Swift Programming Language" docs misleading on subscript #54497

Open
swift-ci opened this issue Jan 21, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. documentation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12061
Radar rdar://problem/58997087
Original Reporter dhoerl (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, Documentation
Assignee None
Priority Medium

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:

subscript(index: Int) -> Int

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:

let foo = myExamplke[index: 1]

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:

subscript(withFloat value: Float) -> Int

Now my head is really spinning! The "under the hood" declaration of the above cannot possible be:

subscript(_ withFloat value: Float) -> Int

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.

subscript(_ withFloat value: Float) -> Int
let foo = myObject[withFloat: 3.3]

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)

@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. documentation
Projects
None yet
Development

No branches or pull requests

2 participants