As far as I can tell, there are two possible overload resolutions: f1 + f3 or f2 + f4.
I thought that these two solutions get an "equivalent score" and therefore there would
be a compile error. However, that's not the case. Instead, the type checker picks
f2 and f4.
So, I guess my question is, whether there is some rule, that prefers
operators, which have the same argument types and the same return type
or whether this is simply a bug.
As far as I can tell, there are two possible overload resolutions: f1 + f3 or f2 + f4.
I thought that these two solutions get an "equivalent score" and therefore there would
be a compile error. However, that's not the case. Instead, the type checker picks
f2 and f4.
So, I guess my question is, whether there is some rule, that prefers
operators, which have the same argument types and the same return type
or whether this is simply a bug.
It’s a bug, and one that I’m aware of, but I’m not aware of anything in JIRA for it. Do you mind opening an issue there and assigning it to me?
Mark
···
On Nov 14, 2016, at 2:05 PM, Toni Suter via swift-users <swift-users@swift.org> wrote:
As far as I can tell, there are two possible overload resolutions: f1 + f3 or f2 + f4.
I thought that these two solutions get an "equivalent score" and therefore there would
be a compile error. However, that's not the case. Instead, the type checker picks
f2 and f4.
So, I guess my question is, whether there is some rule, that prefers
operators, which have the same argument types and the same return type
or whether this is simply a bug.
As far as I can tell, there are two possible overload resolutions: f1 + f3 or f2 + f4.
I thought that these two solutions get an "equivalent score" and therefore there would
be a compile error. However, that's not the case. Instead, the type checker picks
f2 and f4.
So, I guess my question is, whether there is some rule, that prefers
operators, which have the same argument types and the same return type
or whether this is simply a bug.
@David
If you would split up the statement like this...
let x = 0 *** 4
let result = x +++ 0
... the compiler would report an ambiguity error, because both overloads of *** are valid and of equivalent priority.
You could do something like this though:
let x: Int = 0 *** 4 // picks f2
let result = x +++ 0 // picks f4
or this:
let x: String = 0 *** 4 // picks f1
let result = x +++ 0 // picks f3
Now the compiler has enough type information to know which overload to pick.
@Rien
Yes, it is even possible to use the operators as the example above shows, but it is requires a bit more explicit
type information so that the type checker knows which overload to pick.
Thanks and best regards,
Toni
···
Am 15.11.2016 um 08:41 schrieb Rien <Rien@Balancingrock.nl>:
I seem to remember that while it is possible to define, the compiler will yield an error if you try to use the functions (“cannot resolve”).
As far as I can tell, there are two possible overload resolutions: f1 + f3 or f2 + f4.
I thought that these two solutions get an "equivalent score" and therefore there would
be a compile error. However, that's not the case. Instead, the type checker picks
f2 and f4.
So, I guess my question is, whether there is some rule, that prefers
operators, which have the same argument types and the same return type
or whether this is simply a bug.