Consider this example:
protocol P {
associatedtype T
func f() // *
}
extension P {
func f() { print("T is unknown") }
}
extension P where T == Int {
func f() { print("T is Int") }
}
struct X : P {
func f() { print("this one is actually best") }
}
struct Y where U: P, U.T ==
Evidence in favor of Slava's analysis: if you remove `func f()` from P itself,
leaving it in the extensions only, then you get "T is Int" from both calls.
> On Dec 8, 2017, at 12:12 PM, Slava Pestov via swift-users
> wrote:
>
> Hi Jens,
>
> I think the problem is that
Hi Jens,
I think the problem is that overload ranking always prefers a protocol
requirement to a protocol extension member, because usually you want the
dynamic dispatch through the requirement instead of calling the default
implementation. But it appears that this heuristic does not take into
Hi all!
Can someone please explain the rationale behind the last line printing
"T is unknown"
rather than (what I would expect):
"T is Int"
in the following program?
protocol P {
associatedtype T
func f() // *
}
extension P {
func f() { print("T is unknown") }
}
extension P where T
Hi Slava,
Thank you very much for the quick response. As you requested, I filed the bug
under the following link: https://bugs.swift.org/browse/SR-6561
Best Regards
Mario
From: on behalf of Slava Pestov
Date: Thursday, 7 December 2017 at 22:27
To: Mario