Skip to content

[5.1] [CSDiagnostics] Improving the fix-it for defining computed properties #23589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2019
Merged

[5.1] [CSDiagnostics] Improving the fix-it for defining computed properties #23589

merged 1 commit into from
Mar 27, 2019

Conversation

theblixguy
Copy link
Collaborator

Cherry pick of #23500.

This PR offers an improvement when the user is trying to define a computed property that is initialised with a closure. For example:

class Foo {
  var something: Int = { return 0 }
}

We currently emit an error diagnostic for the above, with a fix-it to add ():

Function produces expected type 'Int'; did you mean to call it with '()'?

In case of extensions, we emit:

Extensions must not contain stored properties

With this change, we will offer another fix-it to convert it into a computed property, by removing the = and if the property is immutable, then also changing the let to a var.

Resolves SR-9267.

@theblixguy
Copy link
Collaborator Author

cc @xedin

@xedin
Copy link
Contributor

xedin commented Mar 27, 2019

@swift-ci please test

@xedin xedin merged commit dee5cad into swiftlang:swift-5.1-branch Mar 27, 2019
@theblixguy theblixguy deleted the fix/SR-9267-5.1 branch March 27, 2019 11:00
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.

2 participants