Function overloading ambiguous use - Xcode 12.5

289 Views Asked by At

When I am defining enum:

enum Test: CGFloat {
    case zero
}

and two functions that are similar to the following:

func test(_ param: CGFloat) { 
    print("param - \(param)") 
}

func test(_ param: Test) { 
    print("param - \(param.rawValue)") 
}

Issue when I'm trying to use them:

test(Test.zero) <- prints "param - 0"
test(.zero) <- error: ambiguous use of .zero

While I understand that compiler is clashing with two definitions of .zero, I'm trying to pinpoint where it was changed in release notes of Xcode 12.5. Maybe someone can point me in the right direction? As it seems it's working in 12.4.

Note:

It can be fixed by:

  • Better design of the API;
  • Using @_disfavoredOverload as per following conversation.
1

There are 1 best solutions below

1
On BEST ANSWER

Possibly a secondary consequence of

Implicit member expressions now support chains of member accesses. (57295228)

You might file a bug because existing code broke, but it has an edge case feel so perhaps it should never have worked. In any case I bet saying Test.zero speeds up compilation. This sort of type checking is complicated, as your forum link shows.