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-3483] error: ambiguous reference to member '+' #46071

Closed
swift-ci opened this issue Dec 24, 2016 · 1 comment
Closed

[SR-3483] error: ambiguous reference to member '+' #46071

swift-ci opened this issue Dec 24, 2016 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3483
Radar None
Original Reporter Evilutiuoner (JIRA User)
Type Bug
Status Closed
Resolution Duplicate
Environment

Swift 3.0.2
Xcode 8.2.1

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

md5: 3e35ef14e1aafd5544a1db6cd515dfd3

duplicates:

  • SR-1122 Failure to typecheck chain of binary operators on force-unwrapped values

Issue Description:

This code:

let x: Double? = 1
let sum = x! + x! + x!

returns this error:

error: ambiguous reference to member '+'
let sum = x! + x! + x!
             ^

Workaround:

let x: Double? = 1
let sum = x! as Double + x! + x!
@CodaFi
Copy link
Member

CodaFi commented Dec 31, 2016

I think I've got a good idea of what's happening here. @jtbandes was spot-on with the idea that the problem was the LinkerExprAnalyzer. It was traversing the AST and didn't handle Force-unwrapping, so when it encountered such an expression it recurred into the inner optional expression until it found a declref, then recorded its type. Naturally, that means it thought the result of the linked expression was `Double?` here instead of simply `Double` and tried to propagate this nonsense outward to the rest of the system causing this bogus diagnostic. The fix is 3 lines telling the walker to stop dead.

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

No branches or pull requests

2 participants