Skip to content

Use attribute to designate Union types#82408

Merged
AlekseyTs merged 2 commits into
dotnet:features/Unionsfrom
AlekseyTs:Unions_16
Feb 18, 2026
Merged

Use attribute to designate Union types#82408
AlekseyTs merged 2 commits into
dotnet:features/Unionsfrom
AlekseyTs:Unions_16

Conversation

@AlekseyTs

Copy link
Copy Markdown
Contributor

No description provided.

@AlekseyTs AlekseyTs requested review from a team as code owners February 13, 2026 23:50
@dotnet-policy-service dotnet-policy-service Bot added the Needs API Review Needs to be reviewed by the API review council label Feb 13, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

This PR modifies public API files. Please follow the instructions at https://github.com/dotnet/roslyn/blob/main/docs/contributing/API%20Review%20Process.md for ensuring all public APIs are reviewed before merging.

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@333fred, @RikkiGibson, @dotnet/roslyn-compiler Please review

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

\azp run

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@333fred, @RikkiGibson, @dotnet/roslyn-compiler Please review

if (CSharpAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.UnionAttribute))
{
(attributeData, boundAttribute) = arguments.Binder.GetAttribute(arguments.AttributeSyntax, arguments.AttributeType, beforeAttributePartBound: null, afterAttributePartBound: null, out hasAnyDiagnostics);
if (!attributeData.HasErrors && attributeData.CommonConstructorArguments.IsEmpty)

@RikkiGibson RikkiGibson Feb 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does anything test the significance of attributeData.CommonConstructorArguments.IsEmpty check? #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.

Does anything test the significance of attributeData.CommonConstructorArguments.IsEmpty check?

I do not think so.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think anything can; if it weren't empty, the attribute wouldn't have matched the description, which is for void only. You could consider just asserting, but I'm not overly bothered by the extra check.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note: if you don't have it, it might be good to have a test with an attribute definition like this:

public class UnionAttribute
{
    public UnionAttribute() { }

    [OverloadResolutionPriority(1)]
    public UnionAttribute(int i = 1) { }
}

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.

Note: if you don't have it, it might be good to have a test with an attribute definition like this:

I'll make a note in the Test Plan.

@AlekseyTs AlekseyTs requested a review from a team February 18, 2026 19:51
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@333fred, @dotnet/roslyn-compiler For a second review

if (CSharpAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.UnionAttribute))
{
(attributeData, boundAttribute) = arguments.Binder.GetAttribute(arguments.AttributeSyntax, arguments.AttributeType, beforeAttributePartBound: null, afterAttributePartBound: null, out hasAnyDiagnostics);
if (!attributeData.HasErrors && attributeData.CommonConstructorArguments.IsEmpty)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think anything can; if it weren't empty, the attribute wouldn't have matched the description, which is for void only. You could consider just asserting, but I'm not overly bothered by the extra check.

if (CSharpAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.UnionAttribute))
{
(attributeData, boundAttribute) = arguments.Binder.GetAttribute(arguments.AttributeSyntax, arguments.AttributeType, beforeAttributePartBound: null, afterAttributePartBound: null, out hasAnyDiagnostics);
if (!attributeData.HasErrors && attributeData.CommonConstructorArguments.IsEmpty)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note: if you don't have it, it might be good to have a test with an attribute definition like this:

public class UnionAttribute
{
    public UnionAttribute() { }

    [OverloadResolutionPriority(1)]
    public UnionAttribute(int i = 1) { }
}

@AlekseyTs AlekseyTs requested a review from 333fred February 18, 2026 22:23

@333fred 333fred left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the clarification on existing testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature - Unions Needs API Review Needs to be reviewed by the API review council

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants