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

2017-12-11 Thread Jens Persson via swift-users
The bug has been closed (not a bug). I would appreciate pointers to any thorough documentation on this as I've only found very brief and incomplete descriptions. The information from Mathew et al in this discussion and the comments to the bug-report are the best I've seen so far. /Jens On Sun,

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

2017-12-10 Thread Matthew Johnson via swift-users
Sent from my iPad > On Dec 10, 2017, at 4:30 PM, Jens Persson wrote: > > Thank you Matthew, I will try to digest and incorporate your explanation. > > I'm using a recent snapshot where > struct X : P { > func f() { print("this one is actually best") } > } > compiles

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

2017-12-10 Thread Jens Persson via swift-users
Oh btw Matthew, you wouldn't consider https://bugs.swift.org/browse/SR-6564 a bug then? /Jens On Sun, Dec 10, 2017 at 11:30 PM, Jens Persson via swift-users < swift-users@swift.org> wrote: > Thank you Matthew, I will try to digest and incorporate your explanation. > > I'm using a recent

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

2017-12-10 Thread Matthew Johnson via swift-users
Sent from my iPad > On Dec 10, 2017, at 3:41 PM, Jens Persson via swift-users > wrote: > > I'm trying to get my head around the current behavior, but its very hard to > understand and remember, and judging by the comments here and on my bug > report (SR-6564), so

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