Skip to content

Override completion must not include inaccessible parameter attributes#36163

Merged
ivanbasov merged 3 commits intodotnet:masterfrom
ivanbasov:override
Jun 12, 2019
Merged

Override completion must not include inaccessible parameter attributes#36163
ivanbasov merged 3 commits intodotnet:masterfrom
ivanbasov:override

Conversation

@ivanbasov
Copy link
Copy Markdown
Contributor

Fixes #5646

@ivanbasov ivanbasov added Area-IDE IDE-IntelliSense Completion, Signature Help, Quick Info IDE-CodeStyle Built-in analyzers, fixes, and refactorings labels Jun 4, 2019
@ivanbasov ivanbasov added this to the 16.2.P3 milestone Jun 4, 2019
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)),
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi Jun 4, 2019

Choose a reason for hiding this comment

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

what about overridden properties in VB? they can have parameters too :) #Resolved

@sharwell sharwell removed the IDE-CodeStyle Built-in analyzers, fixes, and refactorings label Jun 5, 2019
@genlu
Copy link
Copy Markdown
Member

genlu commented Jun 5, 2019

Would missing the attribute in overriding method cause anything unexpected if the overridden method is abstract? #Resolved

Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski Jun 5, 2019

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

CyrusNajmabadi commented Jun 5, 2019

Code seems OK, but worried that this is the right thing to do or if we need a less aggressive hammer.

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

@ivanbasov
Copy link
Copy Markdown
Contributor Author

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)

@ivanbasov
Copy link
Copy Markdown
Contributor Author

  • support of property parameters added
  • feedback responded

@CyrusNajmabadi , @genlu , @jasonmalinowski please review

@ivanbasov
Copy link
Copy Markdown
Contributor Author

There is a test failing: TestPropertyReturnTypeAttributes
The test was added by @CyrusNajmabadi to fix http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546779
saying if we copy parameter attributes for properties, we also need to copy return type attributes for properties in case scenario:

Imports System.Runtime.InteropServices
 
Interface I
    Property P(<MarshalAs(UnmanagedType.I4)> x As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
End Interface
 
Class C
    Implements I ' Implement
End Class

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?

@jinujoseph jinujoseph modified the milestones: 16.2.P3, 16.2 Jun 9, 2019
@jasonmalinowski
Copy link
Copy Markdown
Member

jasonmalinowski commented Jun 10, 2019

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.

@ivanbasov
Copy link
Copy Markdown
Contributor Author

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.

@ivanbasov ivanbasov merged commit e9a9904 into dotnet:master Jun 12, 2019
@ivanbasov ivanbasov deleted the override branch June 12, 2019 20:55
@jasonmalinowski jasonmalinowski changed the title Override completion must not include parameter attributes Override completion must not include inaccessible parameter attributes Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE IDE-IntelliSense Completion, Signature Help, Quick Info

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Override completion includes internal attributes when overriding in a different assembly

6 participants