Skip to content

Misc. union changes#82538

Merged
AlekseyTs merged 1 commit into
dotnet:features/Unionsfrom
AlekseyTs:Unions_21
Feb 26, 2026
Merged

Misc. union changes#82538
AlekseyTs merged 1 commit into
dotnet:features/Unionsfrom
AlekseyTs:Unions_21

Conversation

@AlekseyTs

Copy link
Copy Markdown
Contributor

Align implementation with recent design changes:

  • Case types are not nullable types (constructor parameter types are unwrapped)
  • Default nullability of the Value property is no longer inferred from constructors. Annotations on the property declaration itself are used as for any regular property.

Align implementation with recent design changes:
- Case types are not nullable types (constructor parameter types are unwrapped)
- Default nullability of a `Value` property no longer inferred from constructors. Annotations on the property declaration itself are used as for any regular property.
@AlekseyTs

AlekseyTs commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For a second review

@AlekseyTs AlekseyTs requested a review from a team February 25, 2026 22:37

@RikkiGibson RikkiGibson 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.

LGTM with a comment and question.

@@ -22,7 +23,8 @@ public UnionTypeTypeUnionValueSetFactory(NamedTypeSymbol unionType)

private ImmutableArray<TypeSymbol> AdjustedTypesInUnion()

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.

Not blocking: it feels reasonable to remove this helper if we don't end up needing to actually do an adjustment here.

{
public S1(int x) => throw null!;
public S1(bool? x) => throw null!;
public S1(bool x) => throw null!;

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.

Do we have a test where we try to convert null to a union like this?

I'm trying to understand the consequences of using a System.Nullable<T> constructor parameter versus using a T now. It looks like it no longer affects the case types of the union, but it might affect whether null can be converted to the union type? Is that right?

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.

Do we have a test where we try to convert null to a union like this?

I assume you are referring to a union with Nullable<T> as constructor parameter. It doesn't look like we have a test like that, I will add one in another PR.

I'm trying to understand the consequences of using a System.Nullable<T> constructor parameter versus using a T now. It looks like it no longer affects the case types of the union, but it might affect whether null can be converted to the union type? Is that right?

That is correct.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants