# When is the right time to push SE-0068?

**URL:** <https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150>\
**Category:** Discussion\
**Created:** [August 10, 2018, 4:35pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150 "2018-08-10T16:35:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [August 10, 2018, 4:35pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/1 "2018-08-10T16:35:54Z")

</div>

Hi Swift community and all the great devs working on the Swift compiler. I'm wondering when it's finally time to push the implementation of [SE-0068](https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md) forward?

* * *

There is a small but very useful pattern I'd like to implement on a base class type. However this pattern requires the missing feature and has no other way to workaround it (except writing the same boilerplate code over and over).

```swift
protocol Container : AnyObject {
  var coordinator: Coordinator<Self> { get }
}

class Base<T> where T : Container {
  unowned let interface: T

  init(interface: T) {
    self.interface = interface
  }
}

final class Coordinator<T> :
  Base<T> where T : Container {}

class BaseContainer : Container {
  private(set) lazy var coordinator = Coordinator<Self>(interface: self)
                                                  ^~~~
}

```

* * *

I re-read the rationale of the proposal and if I recall correctly someone said once that the core team decided differently then the stated in the rationale. If I'm not mistaken then there will be no `Self` on value types? (Please correct me if I'm wrong.) I personally would really miss it, but `Self` on classes is better then nothing.

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [August 10, 2018, 4:41pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/2 "2018-08-10T16:41:34Z")

</div>

The main issue here has been the poor representation of `Self` in the compiler. Effectively, dynamic `Self` ought to be treated more like a generic parameter in contexts where it's available, but it's currently treated as a special case in the few places it's supported, which is not a scalable model for generalizing where it can be used. We've made incremental progress in improving the model, but there's still a lot of work to do before this would be practical to implement.

---

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [August 10, 2018, 5:00pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/3 "2018-08-10T17:00:31Z")

</div>

Is this:

> [@Joe\_Groff](#):
>
> the poor representation of `Self` in the compiler

anyway important before ABI? By that I mean the things that are missing before the proposal can be implemented will be implemented before or after Swift 5 (not saying that the proposal will be implemented for Swift 5, even if I'd wish for it).

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [August 10, 2018, 5:01pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/4 "2018-08-10T17:01:59Z")

</div>

There shouldn't be any ABI impact.

---

<div class="post-metadata">

**Author:** ![Moximillian](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/moximillian/32/3055_2.png) [@Moximillian](https://forums.swift.org/u/Moximillian)\
**Post date:** [March 16, 2019, 4:44pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/5 "2019-03-16T16:44:04Z")

</div>

Swift 5.1  
[https://github.com/apple/swift/pull/22863](https://github.com/apple/swift/pull/22863)

---

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [March 16, 2019, 4:45pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/6 "2019-03-16T16:45:12Z")

</div>

I know already for a couple month, but thank you nevertheless.

---

<div class="post-metadata">

**Author:** ![Moximillian](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/moximillian/32/3055_2.png) [@Moximillian](https://forums.swift.org/u/Moximillian)\
**Post date:** [March 16, 2019, 4:52pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/7 "2019-03-16T16:52:41Z")

</div>

Yeah, I was thinking to have a ”conclusion” to this thread if someone searches for / stumbles upon this topic

---

<div class="post-metadata">

**Author:** ![johnno1962](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johnno1962/32/6805_2.png) [@johnno1962](https://forums.swift.org/u/johnno1962)\
**Post date:** [March 18, 2019, 10:51pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/8 "2019-03-18T22:51:03Z")

</div>

The implementation has been merged and is available in the [swift.org](https://swift.org/download/#snapshots) nightlies if you want to try it out.

---

<div class="post-metadata">

**Author:** ![linqingmo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/linqingmo/32/2442_2.png) [@linqingmo](https://forums.swift.org/u/linqingmo)\
**Post date:** [March 19, 2019, 2:49am UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/9 "2019-03-19T02:49:36Z")

</div>

I like SE-0068, but it seems there are still many limits.  
`Coordinator<Self>` is still unsupported. `Self` can't work with generic. That means we can't write `[Self]` or `Self?`.

---

<div class="post-metadata">

**Author:** ![johnno1962](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johnno1962/32/6805_2.png) [@johnno1962](https://forums.swift.org/u/johnno1962)\
**Post date:** [March 19, 2019, 2:51pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/10 "2019-03-19T14:51:16Z")

</div>

There are limitations that will have to be sorted out with time including Adrian’s example. You should be able to use [Self] as an argument type on a struct however:

```swift
struct A {

    var v = 99

    static func b(a: [Self]) {
        print("Hello, World! \(a)")
    }

    func a() {
        Self.b(a: [Self.init()])
    }
}

```

For anything else please file a [Jira](https://bugs.swift.org) with example code.

---

<div class="post-metadata">

**Author:** ![Moximillian](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/moximillian/32/3055_2.png) [@Moximillian](https://forums.swift.org/u/Moximillian)\
**Post date:** [March 19, 2019, 3:13pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/11 "2019-03-19T15:13:14Z")

</div>

With the nightly builds, the `as? Self` works great in classes, awesome!

Is there already a further ticket for this?

```swift
    class Foo {
         func bar(closure: (Self) -> Void) {
            ...
          }
    }

```

---

<div class="post-metadata">

**Author:** ![johnno1962](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johnno1962/32/6805_2.png) [@johnno1962](https://forums.swift.org/u/johnno1962)\
**Post date:** [March 19, 2019, 3:22pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/12 "2019-03-19T15:22:01Z")

</div>

I don’t know, feel free to add one. The limitations on Self as a type in method signatures are: only return value if it is a class. See the discussion in [the PR](https://github.com/apple/swift/pull/22863#discussion_r263225089).

---

<div class="post-metadata">

**Author:** ![hamishknight](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hamishknight/32/14226_2.png) [@hamishknight](https://forums.swift.org/u/hamishknight)\
**Post date:** [March 19, 2019, 3:23pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/13 "2019-03-19T15:23:30Z")

</div>

I filed [SR-10121](https://bugs.swift.org/browse/SR-10121) to track that :)

---

<div class="post-metadata">

**Author:** ![linqingmo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/linqingmo/32/2442_2.png) [@linqingmo](https://forums.swift.org/u/linqingmo)\
**Post date:** [March 20, 2019, 1:02am UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/14 "2019-03-20T01:02:42Z")

</div>

```swift
class A {
    required init() {}
    func copy() -> Self {
        let copy = Self.init()
        return copy
    }
    
    var copied: Self {
        let copy = Self.init()
        return copy
    }
}

class B: A {
    override func copy() -> Self {
        let copy = super.copy() as! Self // supported
        return copy
    }
    
    override var copied: Self {
        let copy = super.copied as! Self // unsupported
        return copy
    }
}

```

---

<div class="post-metadata">

**Author:** ![johnno1962](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johnno1962/32/6805_2.png) [@johnno1962](https://forums.swift.org/u/johnno1962)\
**Post date:** [March 20, 2019, 1:15pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/15 "2019-03-20T13:15:00Z")

</div>

Please file a [Jira](https://bugs.swift.org) for this, include #Self in the title so someone can pick them up.

---

<div class="post-metadata">

**Author:** ![linqingmo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/linqingmo/32/2442_2.png) [@linqingmo](https://forums.swift.org/u/linqingmo)\
**Post date:** [March 20, 2019, 3:25pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/16 "2019-03-20T15:25:36Z")

</div>

I filed [SR-10135](https://bugs.swift.org/browse/SR-10135).

---

<div class="post-metadata">

**Author:** ![johnno1962](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johnno1962/32/6805_2.png) [@johnno1962](https://forums.swift.org/u/johnno1962)\
**Post date:** [March 20, 2019, 3:30pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/17 "2019-03-20T15:30:12Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![johnno1962](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johnno1962/32/6805_2.png) [@johnno1962](https://forums.swift.org/u/johnno1962)\
**Post date:** [March 29, 2019, 9:04pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/18 "2019-03-29T21:04:54Z")

</div>

The fix for [SR-10135](https://bugs.swift.org/browse/SR-10135) merged a couple of days ago and should be available in the [swift.org](https://swift.org/download/#snapshots) nightly builds by now. Please kick the tires and answer on the Jira or PR if you find any problems.

---

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [April 6, 2019, 5:05pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/19 "2019-04-06T17:05:45Z")

</div>

Filed an issues. I am I correct that this limitation exists because it was not yet lifted, otherwise I don't see why properties cannot be of type `Self`.

> <https://github.com/apple/swift/issues/52726>
>
> | | |
> |------------------|-----------------|…
> |Previous ID | SR-10326 |
> |Radar | None |
> |Original Reporter | @DevAndArtist |
> |Type | Bug |
> |Status | Resolved |
> |Resolution | Done |
>         
> \<details\>
> \<summary\>Environment\</summary\>
> 
> DEVELOPMENT-SNAPSHOT-2019-04-04-a
> 
> 
> \</details\>
> 
> \<details\>
> \<summary\>Additional Detail from JIRA\</summary\>
> 
> | | |
> |------------------|-----------------|
> |Votes | 0 |
> |Component/s | Compiler |
> |Labels | Bug |
> |Assignee | @johnno1962 |
> |Priority | Medium |
> 
>    
> 
> md5: 00af2a103a18af7ebe8084ad446ae844
> 
> \</details\>
> 
> 
> 
> 
> 
> \*\*Issue Description:\*\*
> 
> 
> This is a strange limitation:
> 
> \`\`\` java
> class A {
> // okay
> func \_self() -\> Self {
> return self
> }
> 
> // error: 'Self' is only available in a protocol or as the result
> // of a method in a class; did you mean 'A'?
> var \_\_self: Self {
> return self
> }
> }
> \`\`\`

---

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [April 6, 2019, 5:11pm UTC](https://forums.swift.org/t/when-is-the-right-time-to-push-se-0068/15150/20 "2019-04-06T17:11:25Z")

</div>

@johnno1962 since we cannot create nested types in protocols yet, `Self` on classes is the first occurrence of the dynamic type that can be captured by a nested type. Does this mean that nested types are (pseudo-)generic?

```swift
class Base {
  typealias _Self = Self
  struct PseudoGeneric {
    var dynamicBase: _Self
  }
}

```

* * *

If we could apply this pattern for nested types in protocols one day, this would be awesome.
