Skip to content

[AST] emitLetToVarNoteIfSimple should also check if the method/accessor is explicitly non-mutating #27641

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 3 commits into from
Oct 14, 2019
Merged

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Oct 12, 2019

emitLetToVarNoteIfSimple() emits a diagnostic with a fix-it to add mutating to a method or accessor. However, it's possible that the method or accessor is explicitly nonmutating. In that case, we end up adding the mutating after nonmutating, leading to another error: Method must not be declared both nonmutating and mutating (if we have a method) or Expected 'get', 'set', 'willSet', or 'didSet' keyword to start an accessor definition (if we have an accessor, like a set).

We should check whether we have an explicit nonmutating attribute and instead of inserting the fix-it, we should replace nonmutating with mutating.

(I noticed when I was writing some tests!)

…ccessor is explicitly 'nonmutating'

Otherwise, we will simply insert the 'mutating' fix-it after 'nonmutating', leading to another error that says both cannot be used at the same time
@theblixguy theblixguy changed the title [AST] emitLetToVarNoteIfSimple should also check if the function is explicitly non-mutating [AST] emitLetToVarNoteIfSimple should also check if the method/accessor is explicitly non-mutating Oct 12, 2019
@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy theblixguy merged commit 3815eff into swiftlang:master Oct 14, 2019
@theblixguy theblixguy deleted the fix/mutating-fix-it branch October 14, 2019 19:09
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