Skip to content

[SR-3318] Operator matching bug #45906

Open
@an0

Description

@an0
mannequin
Previous ID SR-3318
Radar None
Original Reporter @an0
Type Bug
Environment

Swift 3.0.1

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

md5: 198b215af0ca093eeba57a059779685a

Issue Description:

public prefix func - (v: CGVector) -> CGVector {
    return CGVector(dx: -v.dx, dy: -v.dy)
}

public func + (p: CGPoint, v: CGVector) -> CGPoint {
    return CGPoint(x: p.x + v.dx, y: p.y + v.dy)
}

public func - (p: CGPoint, v: CGVector) -> CGPoint {
    return p + (-v)
}

public func - (lhs: CGPoint, rhs: CGPoint) -> CGVector {
    return CGVector(dx: rhs.x - lhs.x, dy: rhs.y - lhs.y)
}


let points = [CGPoint.zero, CGPoint.zero, CGPoint.zero]
let startPoint = points[0] - (points[1] - points[0]) // ambiguous reference to member '-'

Compiler reports this error:

error: ambiguous reference to member '-'
let startPoint = points[0] - (points[1] - points[0])
                                        ^

note: found this candidate
public func - (p: CGPoint, v: CGVector) -> CGPoint {
            ^

note: found this candidate
public func - (lhs: CGPoint, rhs: CGPoint) -> CGVector {
            ^

I don't see how this is ambiguous.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfregressionswift 3.0type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions