Skip to content

Fixed MakeFieldReadonlyCodeFixProvider for volatile fields.#43542

Merged
CyrusNajmabadi merged 3 commits intodotnet:masterfrom
zaytsev-victor:Fixed42759
Apr 22, 2020
Merged

Fixed MakeFieldReadonlyCodeFixProvider for volatile fields.#43542
CyrusNajmabadi merged 3 commits intodotnet:masterfrom
zaytsev-victor:Fixed42759

Conversation

@zaytsev-victor
Copy link
Contributor

Fixes #42759

if (declarationDeclarators.Count == fieldDeclarators.Count())
{
editor.SetModifiers(fieldDeclarators.Key, editor.Generator.GetModifiers(fieldDeclarators.Key) | DeclarationModifiers.ReadOnly);
var modifiers = editor.Generator.GetModifiers(fieldDeclarators.Key) - DeclarationModifiers.Volatile | DeclarationModifiers.ReadOnly;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. using - here is very uncommon. Generally to wipe the bits here it's preferred to do x & ~y.
  2. this pattern is repeated twice. can you extract a helper 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.

This isn't an Enum. DeclarationModifiers doesn't have override for ~ operator.

…ldReadonlyCodeFixProvider.cs

Co-Authored-By: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@CyrusNajmabadi CyrusNajmabadi merged commit d99f93a into dotnet:master Apr 22, 2020
@ghost ghost added this to the Next milestone Apr 22, 2020
@jinujoseph jinujoseph added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Apr 23, 2020
@sharwell sharwell modified the milestones: Next, temp, 16.7.P1 Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE0044 makes volatile fields readonly, resulting in errors

4 participants