gohanlon / swift-memberwise-init-macro

Swift Macro for enhanced automatic inits.
MIT License
122 stars 8 forks source link

Optional `var` properties should default to `nil` for non-public initializers #2

Closed gohanlon closed 1 year ago

gohanlon commented 1 year ago

Description

MemberwiseInit's behavior doesn't match Swift's memberwise init:

struct S {
  var v: String?
}
_ = S()

@MemberwiseInit
struct M {
  var v: String?
}
_ = M()  // 🛑 Compiler error: Missing argument for parameter 'v' in call

MemberwiseInit provides this initializer:

internal init(
  v: String
) {
  self.v = v
}

but, to match Swift's memberwise init, MemberwiseInit should provide:

internal init(
  v: String? = nil
) {
  self.v = v
}

(Thanks, @AndreiChenchik!)

Checklist

swift-memberwise-init-macro version information

0.1.0