# Cannot implement method from protocol which returns Self?

**URL:** https://talk.remobjects.com/t/cannot-implement-method-from-protocol-which-returns-self/12858
**Category:** Silver
**Created:** [April 25, 2017, 10:11am UTC](https://talk.remobjects.com/t/cannot-implement-method-from-protocol-which-returns-self/12858 "2017-04-25T10:11:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jnermut](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/a4c791/32.png) [@jnermut](https://talk.remobjects.com/u/jnermut)
#### Post date: [April 25, 2017, 10:11am UTC](https://talk.remobjects.com/t/cannot-implement-method-from-protocol-which-returns-self/12858/1 "2017-04-25T10:11:11Z")

</div>

Consider the following:

```
protocol AnyPromise
{

	func always() -> Self
}

class Promise: AnyPromise
{

	open func always() -> Self
        {
		return self
        }
}

let x: AnyPromise = Promise()
x.always().always()
```

The purpose of AnyPromise is to be able to use the promise in a type erased fashion and do things with mutliple promises of different types. The return type of Self should be magic and work between protocols and generic classes.

Works ok in a playground:

 ![](https://talk.remobjects.com/uploads/default/original/2X/f/ff7da58477f651f5846b556bbdc984463a64f07b.png)

Fails to compile in Fire / Silver:

 ![](https://talk.remobjects.com/uploads/default/original/2X/5/5d787495b5e03f6684039ef5ad405d31f74aa2d9.png)

/Users/jon/Documents/consoleapplication4222/Program.swift(9,7): error E179: Method “always() → Self” not implemented as required for interface “AnyPromise”  
/Users/jon/Documents/consoleapplication4222/Program.swift(9,7): warning N12: Possible match: Promise!.always() → Self  
/Users/jon/Documents/consoleapplication4222/Program.swift(3,10): warning N4: Type “AnyPromise” was declared here

Returning Promise, and other things I tried, also fails.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [April 25, 2017, 12:13pm UTC](https://talk.remobjects.com/t/cannot-implement-method-from-protocol-which-returns-self/12858/2 "2017-04-25T12:13:36Z")

</div>

I believe `Self` on protocols is not yet fully supported, due to limitations of the generic type system on some of the platforms. It’s something we’re looking into improving.

---

<div class="post-metadata">

### Author: ![jnermut](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/a4c791/32.png) [@jnermut](https://talk.remobjects.com/u/jnermut)
#### Post date: [April 25, 2017, 12:18pm UTC](https://talk.remobjects.com/t/cannot-implement-method-from-protocol-which-returns-self/12858/3 "2017-04-25T12:18:15Z")

</div>

I figured, thanks. For this particular method I had to workaround with a different method which returns nothing.  
By the way, did you see this - I’m guessing most of these projects depend on Foundation, but may be useful?

> **[Swift Source Compatibility Test Suite Now Available](https://swift.org/blog/swift-source-compatibility-test-suite/)**
>
> We are pleased to announce the release of a new Swift source compatibility test
> suite as part of the effort
> to maintain source compatibility in future Swift releases.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [April 25, 2017, 2:49pm UTC](https://talk.remobjects.com/t/cannot-implement-method-from-protocol-which-returns-self/12858/4 "2017-04-25T14:49:40Z")

</div>

Something worth looking at, yes.
