"Generate Equals" should ignore indexers and setter-only properties#25700
"Generate Equals" should ignore indexers and setter-only properties#25700DustinCampbell merged 8 commits intodotnet:masterfrom
Conversation
|
@CyrusNajmabadi Would you take a quick look at this? Thanks |
|
|
||
| <WorkItem(25690, "https://github.com/dotnet/roslyn/issues/25690")> | ||
| <Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)> | ||
| Public Async Function TestWithDialogNoIndexer() As Task |
There was a problem hiding this comment.
note: this is not an indexer for VB, it's a parameterized property. To make an indexer, you need to use "default property". I would consider adding a test for both cases.
There was a problem hiding this comment.
I think i've seen this referred to as an "indexer property" in the docs
There was a problem hiding this comment.
Internally, we've always called them "parameterized properties". Indexers use the "Default" keyword.
|
@CyrusNajmabadi I made other changes to fix one more issue, you might want to review again. |
| IsWritableFieldOrProperty(symbol); | ||
| => !symbol.IsStatic && | ||
| (symbol is IFieldSymbol field && IsViableField(field) && !field.IsConst || | ||
| symbol is IPropertySymbol property && IsViableProperty(property) && property.IsWritableInConstructor()); |
There was a problem hiding this comment.
this mix of &&'s and ||'s is confusing. Please extract into helper and parenthesize to keep precedence clear. In general, we prefer expressions that are uniform with &&'s or ||'s.
There was a problem hiding this comment.
I thought about this for a while and found it hard to extract common code between IsWritableInstanceFieldOrProperty and IsReadableInstanceFieldOrProperty. They use the same logic for whether the field/property is "viable" but they also need to do more checks that are still specific to each type. Basically one method would check the type and some condition, and the other one would check the type again for another condition. So I don't know what to do there.
There was a problem hiding this comment.
IsWritableInstanceFieldOrProperty
IsReadableInstanceFieldOrProperty
Based on the name, it sounds like they can reuse whatever computes if this is an InstanceFieldOrProperty
Then you can have code that checks if it's Readable or Writable.
There was a problem hiding this comment.
I thought about this for a while and found it hard to extract common code
Right now the mixing of precedence operators is confusing here. Please at least parenthesize for clarity. Also, to prevent mixing and matching of operators, just make this a full body method. THis is complex enough that collapsing into an expression is harder to understand.
There was a problem hiding this comment.
Based on the name, it sounds like they can reuse whatever computes if this is an InstanceFieldOrProperty
Yes. But then you'd still have another method for IsWritableInstanceFieldOrProperty which would have the same structure - it needs to check writability based on whether the symbol is a field or a property. So the code reuse would actually reuse some things but duplicate other things, and introduce unnecessary type checks after we already did the same check before.
CyrusNajmabadi
left a comment
There was a problem hiding this comment.
Please refactor the complex expressions to give precedence to clarity.
interesting way to phrase things 😃 |
| { | ||
| switch (symbol) | ||
| { | ||
| case IFieldSymbol field when IsViableField(field): return true; |
There was a problem hiding this comment.
can you not just do: case IFieldSymbol field: return IsViableField(field);? It seems much simpler than having 'when' and a boolean.
| switch (symbol) | ||
| { | ||
| case IFieldSymbol field when IsViableField(field): return true; | ||
| case IPropertySymbol property when IsViableProperty(property): return !property.IsWriteOnly; |
There was a problem hiding this comment.
same issue here. no need for 'when'. just merge its condition into the actual return statement.
There was a problem hiding this comment.
I found this a little nicer than having && inside each case but ok
| => !symbol.IsStatic && | ||
| (symbol is IFieldSymbol field && IsViableField(field) && !field.IsConst || | ||
| symbol is IPropertySymbol property && IsViableProperty(property) && property.IsWritableInConstructor()); | ||
| => !symbol.IsStatic && IsWritableFieldOrProperty(symbol); |
There was a problem hiding this comment.
these two methods are very readable. thank you :)
CyrusNajmabadi
left a comment
There was a problem hiding this comment.
Thanks for the change. LGTM.
|
retest windows_debug_vs-integration_prtest please |
|
retest windows_release_vs-integration_prtest please |
|
retest windows_release_unit32_prtest please |
1 similar comment
|
retest windows_release_unit32_prtest please |
|
@dotnet-bot retest windows_release_unit64_prtest please |
|
@dotnet-bot retest this please |
|
retest windows_debug_unit32_prtest please |
|
@dotnet-bot retest this please |
|
I think some of those tests are stuck. I have this on another PR as well and retesting doesn't help. |
|
Yeah, @jaredpar just sent email internally about it. The Jenkins machines are stuck, but it's being looked at. |
|
retest windows_debug_spanish_unit32_prtest please |
|
retest windows_release_vs-integration_prtest please |
|
retest windows_debug_spanish_unit32_prtest please |
1 similar comment
|
retest windows_debug_spanish_unit32_prtest please |
|
@jaredpar: Is the windows_debug_spanish_unit32_prtest flaky at the moment? We've run it a few times, but we keep getting back, "xunit produced no error output but had exit code 1" |
|
@DustinCampbell looks like the EE tests are just faky in general. Seen this in a few logs |
|
OK to merge? |
|
It's fine by me. |
|
Great! @Neme12: Thanks very much for your contributions! |
|
Thanks, I still have 12 other PRs if you're interested 😄 |
fixes #25690
fixes #25707