Skip to content

Conversation

@333fred
Copy link
Member

@333fred 333fred commented Apr 25, 2025

In C#, we filter out CompilerFeatureRequired and Obsolete attributes from GetAttribute calls when we understand their meaning, instead of surfacing them in the public API. This can have downstream effects in the IDE, such as appearing as though these constructors are deprecated. We now do the same in VB. Closes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2436215.

… symbols

In C#, we filter out CompilerFeatureRequired and Obsolete attributes from GetAttribute calls when we understand their meaning, instead of surfacing them in the public API. This can have downstream effects in the IDE, such as appearing as though these constructors are deprecated. We now do the same in VB. Closes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2436215.
@333fred 333fred added the Feature - Required Members Required properties and fields label Apr 25, 2025
@333fred 333fred requested a review from AlekseyTs April 25, 2025 00:50
@333fred 333fred requested a review from a team as a code owner April 25, 2025 00:50
@ghost ghost added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 25, 2025
Dim attributeData As ImmutableArray(Of VisualBasicAttributeData) = Nothing
Dim containingPEModuleSymbol = DirectCast(ContainingModule(), PEModuleSymbol)
containingPEModuleSymbol.LoadCustomAttributes(Me.Handle, attributeData)
Dim checkForRequiredMembers = MethodKind = MethodKind.Constructor AndAlso
Copy link
Member Author

Choose a reason for hiding this comment

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


Dim comp = CreateCompilation(vbCode, {cComp.EmitToImageReference()})
comp.AssertNoDiagnostics
Dim comp = CreateCompilation(vbCode, {cComp.EmitToImageReference()}, targetFramework:=TargetFramework.Net70)
Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out some of these compilations were not targeting a version of .NET with SetsRequiredMembers in it, which was then giving missing symbol text in ToTestDisplayString().

attributeData = containingPEModuleSymbol.GetCustomAttributesForToken(
Me.Handle,
filteredOutAttribute1:=discard1,
filterOut1:=If(compilerFeatureRequiredDiagnostic Is Nothing, AttributeDescription.CompilerFeatureRequiredAttribute, Nothing),
Copy link
Contributor

Choose a reason for hiding this comment

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

compilerFeatureRequiredDiagnostic Is Nothing

Do we have a test observing significance of this condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I didn't cook up some invalid IL test here. If you'd prefer that I do so, I can.

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we have a test for C#, it feels like it shouldn't be very hard to port it.

Copy link
Member Author

Choose a reason for hiding this comment

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

We didn't, but now we do.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 1)

@333fred
Copy link
Member Author

333fred commented Apr 25, 2025

@dotnet/roslyn-compiler for a second review

@333fred
Copy link
Member Author

333fred commented Apr 28, 2025

@dotnet/roslyn-compiler for a second review.

filteredOutAttribute1:=discard1,
filterOut1:=If(compilerFeatureRequiredDiagnostic Is Nothing, AttributeDescription.CompilerFeatureRequiredAttribute, Nothing),
filteredOutAttribute2:=discard2,
filterOut2:=If(ObsoleteAttributeData Is Nothing, AttributeDescription.ObsoleteAttribute, Nothing))
Copy link
Contributor

Choose a reason for hiding this comment

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

If(ObsoleteAttributeData Is Nothing, AttributeDescription.ObsoleteAttribute, Nothing)

Does this filter out explicit [Obsolete] attributes as well (for a constructor on a type with a required member that has been deprecated)?

Copy link
Member Author

Choose a reason for hiding this comment

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

@333fred 333fred merged commit 6911efb into dotnet:main Apr 29, 2025
24 checks passed
@333fred 333fred deleted the vb-required-filter branch April 29, 2025 17:50
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 29, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature - Required Members Required properties and fields untriaged Issues and PRs which have not yet been triaged by a lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants