Navigation Menu

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-6118] mechanism to hand through #file/#line in subscripts #48673

Closed
weissi opened this issue Oct 11, 2017 · 4 comments
Closed

[SR-6118] mechanism to hand through #file/#line in subscripts #48673

weissi opened this issue Oct 11, 2017 · 4 comments
Assignees
Labels
compiler The Swift compiler in itself default arguments Feature: default arguments for value parameters feature A feature request or implementation subscript Feature: Subscript declarations

Comments

@weissi
Copy link
Member

weissi commented Oct 11, 2017

Previous ID SR-6118
Radar None
Original Reporter @weissi
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels New Feature
Assignee @slavapestov
Priority Medium

md5: b802d9f73456058327d450079e18b6e4

Issue Description:

For my hypothetical MyArray implementation, in normal functions I can write

function get(index: Int, file: StaticString = #file, line: UInt = #line) -> Value {
    if !checkIndex(index) {
        fatalError("index \(index) out of bound", file: file, line: line)
    }
    ...
}

and I'll be able to create good error messages for the user.

In subscripts however, default arguments are disallowed so

subscript(index: Int) -> Value {
    if !checkIndex(index) {
        fatalError("index \(index) out of bound")
    }
    ....
}

will always show its literal line and file rather than the callers.

@belkadan
Copy link
Contributor

belkadan commented Oct 11, 2017

That should look like this:

struct A {
  subscript(a: Int, file: String = #file) -> Int {
    print(file)
    return a
  }
}

print(A()[1])

but we don't allow default arguments in subscripts at the moment (because it's unclear how they would work with inout subscripts).

@weissi
Copy link
Member Author

weissi commented Nov 16, 2017

@belkadan, sorry, could you expand on the inout subscripts? I don't know what they are 🙂

@slavapestov
Copy link
Member

#23734

@swift-ci
Copy link
Collaborator

Comment by Joseph Twomey (JIRA)

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation default arguments Feature: default arguments for value parameters subscript Feature: Subscript declarations and removed new feature labels Feb 2, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself default arguments Feature: default arguments for value parameters feature A feature request or implementation subscript Feature: Subscript declarations
Projects
None yet
Development

No branches or pull requests

5 participants