Skip to content

Conversation

@vishakha1411
Copy link
Contributor

Fixes async/throws being dropped when converting zero-parameter functions to computed properties. Fixes #3235
Tested locally. Please let me know if you’d like me to make any changes or add test cases.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test case for this? Also, could you ensure that we only produce the explicit get accessor if there are effect specifiers? I believe the current tests should check that, did you run them?

@vishakha1411
Copy link
Contributor Author

I have added test cases. Also, he implementation now only generates an explicit get accessor when effect specifiers (async and/or throws) are present; otherwise, it continues to use the implicit getter as before.
I’ve run the full ConvertZeroParameterFunctionToComputedPropertyTests suite locally, and all tests are passing.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two high-level comments before I go into an in-depth review: Could you please ensure that your PR does not contain unnecessary formatting changes? Also, instead of hard-coding 2 spaces as the indentation could you use BasicFormat.inferIndentation to infer the indentation from the source file?

@vishakha1411
Copy link
Contributor Author

I updated the code to use BasicFormat.inferIndentation(of: syntax) so the refactoring follows the source file’s indentation.
From what I understood when looking at the implementation, inferIndentation returns nil when there are fewer than three indented lines in the function body. So I have kept the .spaces(2) fallback as well.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @vishakha1411 ❤️ I have one comment below, otherwise this looks good.

let accessorBlock: AccessorBlockSyntax

if let accessorEffectSpecifiers {
let indentedStatements = body.statements.map { $0.with(\.leadingTrivia, $0.leadingTrivia + indentation) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not indent multi-line statements, eg. the following. Could you use body.statements.indented which handles all of this?

func foo() async {
  bar(
    1
  )
}

Also, please add a test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replaced this with body.statements.indented and also added a couple of test cases for the same.

Comment on lines 87 to 89
accessors: .accessors(
AccessorDeclListSyntax([getAccessor])
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Fits on one line

Suggested change
accessors: .accessors(
AccessorDeclListSyntax([getAccessor])
),
accessors: .accessors(AccessorDeclListSyntax([getAccessor])),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you 👍🏽

@ahoppen
Copy link
Member

ahoppen commented Jan 31, 2026

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge January 31, 2026 06:15
@ahoppen
Copy link
Member

ahoppen commented Jan 31, 2026

Could you run swift-format on your changes as described in CONTRIBUTING.md?

auto-merge was automatically disabled January 31, 2026 14:25

Head branch was pushed to by a user without write access

@ahoppen
Copy link
Member

ahoppen commented Feb 1, 2026

@swift-ci Please test

1 similar comment
@ahoppen
Copy link
Member

ahoppen commented Feb 1, 2026

@swift-ci Please test

@ahoppen ahoppen merged commit e68efa0 into swiftlang:main Feb 3, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Converting zero-parameter function to computed property drops async and throws

2 participants