Convert struct initializers to Swift memberwise initializers

Description

:

converts to:

... but could optimally produce:

Note: according to https://github.com/apple/swift-evolution/blob/master/proposals/0018-flexible-memberwise-initialization.md

The default memberwise initializer behavior of Swift has at least these deficiencies (IMO):
1) Defining a custom init in a struct disables the memberwise initializer, and there is no easy way to get it back.

... so this may not work for all cases. Needs research to confirm.

Environment

None

Activity

Show:
Alex Petuschak
February 24, 2020, 4:19 PM

Implemented as suggested.

Note that memberwise initialization cannot be used:

  1. For nested field initialization. We are using a fallback approach and generate regular field initialization expressions here. Example: ShouldConvertC99StructInitializerInReturnStatement test.

2. When fields are initialized in a non-default order, or not all fields are initialized.

Currently, we are not using a fallback approach here (hoping that such cases will be rare enough).

Assignee

Alex Petuschak

Reporter

Alex Petuschak

Labels

None

Git Branch Name

None

GitHub Issue

None

Components

Fix versions

Priority

Medium
Configure