Override completion must not include inaccessible parameter attributes#36163
Override completion must not include inaccessible parameter attributes#36163ivanbasov merged 3 commits intodotnet:masterfrom
Conversation
| modifiers: modifiers, | ||
| // There is no need for an override to have same parameters attributes as the original method. | ||
| // Just clear attributes when generating an override. | ||
| parameters: overriddenMethod.Parameters.SelectAsArray(p => p.WithAttributes(ImmutableArray<AttributeData>.Empty)), |
There was a problem hiding this comment.
what about overridden properties in VB? they can have parameters too :) #Resolved
|
Would missing the attribute in overriding method cause anything unexpected if the overridden method is abstract? #Resolved |
jasonmalinowski
left a comment
There was a problem hiding this comment.
Code seems OK, but worried that this is the right thing to do or if we need a less aggressive hammer.
| method: overriddenMethod, | ||
| accessibility: overriddenMethod.ComputeResultantAccessibility(newContainingType), | ||
| modifiers: modifiers, | ||
| // There is no need for an override to have same parameters attributes as the original method. |
There was a problem hiding this comment.
I worry this is a bit strong of a statement that there's no need -- how do we know there aren't some reflection-based systems out there that are depending on this?
Which attributes triggered this original question? #Resolved
There was a problem hiding this comment.
We already do not copy attributes of methods and attributes of properties. By mistake (my opinion), we copy attributes of method parameters and property parameters. We just should stop doing this.
In reply to: 290869693 [](ancestors = 290869693)
FWIW, i think this is totally ok. I recall us doing this in many other scenarios (maybe implement interface) and it really hasn't been a problem. This feels more like a missed case, versus something that is important to preserve behavior on. #Resolved |
src/Workspaces/Core/Portable/CodeGeneration/CodeGenerationSymbolFactory.cs
Show resolved
Hide resolved
|
As far as I know, member signatures do not depend on attributes. In some cases, one may want some attributes to be copied or added. However, we do not need to guarantee this. If you have an example of the opposite, we definitely should consider it. In reply to: 499193025 [](ancestors = 499193025) |
@CyrusNajmabadi , @genlu , @jasonmalinowski please review |
|
There is a test failing: This is the concern that @genlu and @jasonmalinowski mentioned. The question is: do we need to copy attributes for any purpose? I'd say - no. See ideas in comments above. @CyrusNajmabadi , @jasonmalinowski , @genlu - your thoughts? |
|
The COM marshalling case does seem worrisome: I would be most surprised if the CLR walked to the base type to find the marshalling attributes before knowing how to marshal things. And in that case, those attributes are 100% critical to the correct functioning of the method. More generally, the only way this is safe to blanket apply to all methods is if we know that every framework using reflection or metadata walking is going to look to the base type. That's a huge proof I don't think we can possibly make. And I can go and write a code that undoes your proof even if you did enumerate every package on NuGet. Looking at the other bug, if the concern is NullableAttribute then we should close this PR and dupe it against one of the work items for nullable, since we need to address that attribute holistically and we're still having conversations about the best way to do it. In any case, this PR isn't the right way to fix that. If some other attribute is causing us to look at this then let's discuss that attribute -- but otherwise I'd absolutely close this PR and by design the original bug, making sure we have a tracking bug for NullableAttribute as appropriate. |
|
Synced with @jasonmalinowski offline. Agreed to keep accessible attributes only. Decided to add a method to determine attributes to be kept vs attributes to be dropped. @jasonmalinowski will extend it for other purposes later. @jasonmalinowski , @genlu , @CyrusNajmabadi please review. |
Fixes #5646