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-2354] inout parameter in subscript gives the wrong error message #44961

Closed
swift-ci opened this issue Aug 16, 2016 · 4 comments
Closed

[SR-2354] inout parameter in subscript gives the wrong error message #44961

swift-ci opened this issue Aug 16, 2016 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers parser Area → compiler: The legacy C++ parser

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2354
Radar None
Original Reporter chriseidhof (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, Parser, StarterBug
Assignee @CodaFi
Priority Medium

md5: 0bbd574dd373c16d9585687e14bb250e

Issue Description:

When I try to have an `inout` parameter in a subscript, the compiler won't let me compile:

struct X {
    subscript(x: inout Int) -> () {
      x += 1
    }
}

However, the error message could be improved. The current message is: "Parameters may not have the 'var' specifier". This should probably be something like "Subscript parameters may not have the 'inout' specifier".

@belkadan
Copy link
Contributor

I don't see any error at all until the call site in Swift 3, but either way we should fix this.

@swift-ci
Copy link
Collaborator Author

Comment by Ryan Collins (JIRA)

@belkadan chriseidhof (JIRA User)

I'm having trouble getting the compiler to throw this error at all. Do you have an example project?

My test project to try to get the compiler to throw that error is here: https://github.com/rymcol/SR2354 (using DEVELOPMENT-SNAPSHOT-2016-08-23-a)

@belkadan
Copy link
Contributor

I think that must have just recently changed. We still reject it at the call site, though, so we probably should be rejecting it at the declaration site.

struct X {
    subscript(x: inout Int) -> () {
      x += 1
    }
}

func test(_ x: X) {
  var y = 1
  print(x[&y])
  print(y)
}
test(X())

@CodaFi
Copy link
Member

CodaFi commented May 5, 2017

Resolved by #9147.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

3 participants