Re: [swift-users] Swift's method dispatch

2017-12-08 Thread Jordan Rose via swift-users
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 ==

Re: [swift-users] Swift's method dispatch

2017-12-08 Thread Greg Parker via swift-users
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

Re: [swift-users] Swift's method dispatch

2017-12-08 Thread Slava Pestov via swift-users
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

[swift-users] Swift's method dispatch

2017-12-08 Thread Jens Persson via swift-users
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

Re: [swift-users] Multiple Class Types in Protocol Composition

2017-12-08 Thread Mario Meili via swift-users
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