# SE-0242: Synthesize default values for the memberwise initializer

**URL:** <https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618>\
**Category:** Proposal Reviews\
**Created:** [February 18, 2019, 4:35pm UTC](https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618 "2019-02-18T16:35:24Z")\
**Posts on this page:** 4\
**Page:** 6

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [March 12, 2019, 10:11pm UTC](https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618/101 "2019-03-12T22:11:13Z")

</div>

Forum post here: [User defined initializers always call member initializers](https://forums.swift.org/t/user-defined-initializers-always-call-member-initializers/21533)

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [March 13, 2019, 4:58am UTC](https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618/102 "2019-03-13T04:58:19Z")

</div>

> [@tkremenek](#):
>
> The Core Team felt that this was a bug in the compiler's implementation of initializers. The failure here is that Bar calls the side effect, and it is not the right behavior. Addressing this would likely require an evolution proposal, or at least an assessment of whether or not fixing this would break existing code.

I strongly disagree that this is a bug. Initial value expressions should not have side effects, ideally, and if they do, it is easier to reason about them if we just say that they are always executed at the top of the initializer, than if where and when they're executed depends on the DI analysis.

To put it another way, initial value expressions are simple syntax sugar that you can eliminate by writing out the initialization by hand in each initializer; if your initial value expressions have side effects or don't always need to run for other reasons, it is best to avoid them altogether and write out the initializer body explicitly.  
y

---

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [March 14, 2019, 6:41am UTC](https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618/103 "2019-03-14T06:41:00Z")

</div>

How is this handled for `let` members? If a stored `let` property has a default value and it can be set in an initializer, then it's set only once, right? `var` properties could be set to use a similar rule.

---

<div class="post-metadata">

**Author:** ![lancep](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lancep/32/1509_2.png) [@lancep](https://forums.swift.org/u/lancep)\
**Post date:** [March 14, 2019, 3:27pm UTC](https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618/104 "2019-03-14T15:27:19Z")

</div>

let properties that have default values cannot be reassigned in an initializer.

```swift
struct Test { 
   let id = 10 
   init(id: Int) { 
       self.id = id 
   } 
 } 
error: repl.swift:8:17: error: immutable value 'self.id' may only be initialized once
        self.id = id

```

[Previous page](https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618.md?page=5)
