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-10548] "use of extraneous '&'" when trying to += an Int? subscript #52948

Closed
TellowKrinkle opened this issue Apr 25, 2019 · 1 comment
Closed
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 type checker Area → compiler: Semantic analysis

Comments

@TellowKrinkle
Copy link

Previous ID SR-10548
Radar None
Original Reporter @TellowKrinkle
Type Bug
Status Resolved
Resolution Done
Environment

Used Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.4)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: cbe23b6cafadd8bae7967e536b1c7533

Issue Description:

The following code invokes the diagnostic "use of extraneous '&'". The compiler offers a fix-it that deletes the variable name from the subscript, leaving just the subscript operator left.

var dic = [Int: Int]() 
dic[3] += 1

Expected:

Some error relating to the fact that we're trying to use `+=` on an `Int?`

@belkadan
Copy link
Contributor

Looks like it's fixed on master!

<stdin>:2:4: error: value of optional type 'Int?' must be unwrapped to a value of type 'Int'
dic[3] += 1
   ^
<stdin>:2:4: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
dic[3] += 1
   ^
      !

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants