# About reassigning self in classes

**URL:** <https://forums.swift.org/t/about-reassigning-self-in-classes/33813>\
**Category:** Using Swift\
**Created:** [February 14, 2020, 8:10am UTC](https://forums.swift.org/t/about-reassigning-self-in-classes/33813 "2020-02-14T08:10:41Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Jens](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jens/32/12903_2.png) [@Jens](https://forums.swift.org/u/Jens)\
**Post date:** [February 14, 2020, 1:28pm UTC](https://forums.swift.org/t/about-reassigning-self-in-classes/33813/7 "2020-02-14T13:28:11Z")

</div>

But the effect is the same (see demonstration program in OP) no matter if the reassignment is done via a default protocol implementation of a method, or if it had been allowed in a method on the class.

And unless I'm misunderstanding the following:

> [@Mutating Function on Class Type (Possible bug?)](https://forums.swift.org/t/mutating-function-on-class-type-possible-bug/15066/7):
>
> One thing I have wondered about related to this issue is why Swift does not allow writing:
> 
> ```swift
> class Foo {
> mutating func bar() {
> self = Foo()
> }
> }
> 
> ```

> [@Mutating Function on Class Type (Possible bug?)](https://forums.swift.org/t/mutating-function-on-class-type-possible-bug/15066/8):
>
> We could allow it, sure. But it would only change _this_ reference, not any other references pointing to the same object, and _not_ having `mutating` doesn't prevent you from changing stored properties (see [Avoiding unbreakable reference cycle with value types and closures?](https://forums.swift.org/t/avoiding-unbreakable-reference-cycle-with-value-types-and-closures/18757/17)). So it's left out of the language to avoid introducing a point of confusion.

The answer from @jrose seems to suggest that assigning self of a class (no matter how) is something that is meant to be left out of the language.

But it's _not_ left out of the language (as shown by the demonstration program). And I'd like to know if it is

1. Expected behavior, working as designed (and if so, why allowing this indirect form that can happen accidentally via a default implementation of a protocol, while disallowing the explicit form in the class)?
2. An unfortunate by-product that can't be helped
3. A bug (ie it shouldn't be allowed, because it's meant to be "left out of the language to avoid introducing a point of confusion").

---

_[View the full topic](https://forums.swift.org/t/about-reassigning-self-in-classes/33813)._
