> On 12 Mar 2017, at 08:21, Xiaodi Wu <[email protected]> wrote:
> 
> Sorry, I'm confused. The following works:
> 
> ```
> protocol Promise {
>   associatedtype Result
> }
> 
> protocol Scanner {
>   associatedtype ScannerPromise : Promise
>   func frobnicate<T>(_: T) -> ScannerPromise
>     where ScannerPromise.Result == T
> }
> ```
> 
> Why does it matter if `ScannerPromise` is generic or not?
> 

That’s some pretty strange syntax. I admit I didn’t even try that. 
ScannerPromise would necessarily have to be generic in this context, because I 
want to bind one of its associated types to a generic parameter from a 
function. There is no way a non-generic type could do that.

That said, even though the compiler accepts your code, it doesn’t seem to 
actually work:

protocol Promise {
  associatedtype Result
  func await() -> Result
}

protocol Scanner {
  associatedtype ScannerPromise : Promise
  func frobnicate<T>(_: T) -> ScannerPromise
    where ScannerPromise.Result == T
}

func use<S: Scanner, T>(_ s: S, _ t: T) -> T {
        return s.frobnicate(t).await()
}
            

3.0.2: Segfault

3.1:

error: repl.swift:13:14: error: cannot invoke 'frobnicate' with an argument 
list of type '(T)'
    return s.frobnicate(t).await()
             ^

repl.swift:13:14: note: expected an argument list of type '(T)'
    return s.frobnicate(t).await()

- Karl
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to