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-10818] Strange compiler error message #53208

Closed
swift-ci opened this issue Jun 1, 2019 · 4 comments
Closed

[SR-10818] Strange compiler error message #53208

swift-ci opened this issue Jun 1, 2019 · 4 comments
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

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 1, 2019

Previous ID SR-10818
Radar None
Original Reporter GarthSnyder (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.14.5

Xcode 10.2

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

md5: fc72cd5b7a4817c7508f5b5e261bfbb8

Issue Description:

let nums = [1, 2, 3]
var foo: [Int: Int] = [:]
for num in nums {
    foo[num] += 1 // Error: "Use of extraneous '&'"
}

There is an error in the optionality handling here, but the error message could be more on target.

@belkadan
Copy link
Contributor

belkadan commented Jun 3, 2019

Looks like it's been fixed in master!

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

@xedin, do you know if we have a test case like this in the test suite already?

@xedin
Copy link
Member

xedin commented Jun 3, 2019

@belkadan I think I have added similar one while porting diagnostics from missing unwrap to new diagnostic framework but I'll take a closer look. This is also fixed in 5.1 branch.

@xedin
Copy link
Member

xedin commented Jun 3, 2019

@belkadan
Copy link
Contributor

belkadan commented Jun 3, 2019

Thanks, Pavel, and thanks Garth for filing!

@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

3 participants