Skip to content

Misc. Union changes#82448

Merged
AlekseyTs merged 1 commit into
dotnet:features/Unionsfrom
AlekseyTs:Unions_18
Feb 20, 2026
Merged

Misc. Union changes#82448
AlekseyTs merged 1 commit into
dotnet:features/Unionsfrom
AlekseyTs:Unions_18

Conversation

@AlekseyTs

Copy link
Copy Markdown
Contributor
  • Null pattern for classes
  • TryGetValue nullable analysis

- Null pattern for classes
- TryGetValue nullable analysis
applyMemberPostConditions(receiverSlot, type, notNullWhenFalseMembers, ref StateWhenFalse);
}

if (method is MethodSymbol

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.

It might be reasonable to share the isTryGetValueSignature helper from GetUnionTypeTryGetValueMethod here.

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.

It might be reasonable to share the isTryGetValueSignature helper from GetUnionTypeTryGetValueMethod here.

If I remember correctly the logic doesn't match exactly.

CompileAndVerify(comp1, expectedOutput: "1323 -1-3-2-3").VerifyDiagnostics(
// (26,50): hidden CS9335: The pattern is redundant.
// return u switch { int => 1, string => 2, null => 3 };
Diagnostic(ErrorCode.HDN_RedundantPattern, "null").WithLocation(26, 50),

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

This warning still seems misleading, per the prototype comment from before this change. Should the prototype comment be restored? #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.

This warning still seems misleading, per the prototype comment from before this change. Should the prototype comment be restored?

No the hidden diagnostic is expected now, null can be replaced with an _ and the meaning won't change

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 keep missing the HDN_ prefix on these.

@RikkiGibson

Copy link
Copy Markdown
Member

Test failure looks like an infra issue.

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

Copy link
Copy Markdown
Contributor Author

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

1 similar comment
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

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

RefKind: RefKind.None,
Parameters: [{ RefKind: RefKind.Out, Type: var parameterType }]
} tryGetValue &&
tryGetValue.ContainingType is { IsUnionType: true } unionType &&

@333fred 333fred Feb 19, 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.

Small nit: this could be integrated into the previous pattern. #Pending

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