Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The change affects core nullable flow analysis, and CI is still running.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes union nullability state restoration after reassignment.
Changes:
- Applies union-specific
Valuedefaults during member-state inheritance. - Adds regression coverage for standard and member-provider unions.
| File | Description |
|---|---|
NullableWalker.cs |
Corrects reassignment flow state. |
UnionsTests.cs |
Covers reported and related scenarios. |
|
@RikkiGibson, @jjonescz, @dotnet/roslyn-compiler Please review |
| { | ||
| Result<string, int> r = Make(); | ||
| #line 100 | ||
| System.Console.WriteLine(r switch { string s => s, int f => $""{f}"" }); |
There was a problem hiding this comment.
Can we add some versions of this where null is an explicit case in the switch, even though it's still Result<string, int> without string??
| _variables[containingSlot].Symbol.GetTypeOrReturnType().Type is NamedTypeSymbol { IsUnionType: true, UnionCaseTypesNoUseSiteDiagnostics: not [] } unionType && | ||
| Binder.IsUnionTypeValueProperty(unionType, property)) | ||
| { | ||
| return unionType.UnionValueDeclaredNullableFlowState; |
There was a problem hiding this comment.
I am wondering if this adjustment should be moved even "deeper" into the stack. For example, within GetTypeOrReturnTypeWithAnnotations(), or ApplyUnconditionalAnnotations(), or a new helper which is called from similar places as those methods.
The reason I bring this up is, it looks like there are still places where the flow state of the Value doesn't match what we expect. For example, in the following test, a warning is reported in M1().Value.ToString(), but not on u.Value.ToString().
[Fact]
public void M()
{
var source = """
#nullable enable
class Program
{
U M1() => 42;
void M2()
{
M1().Value.ToString();
}
void M3()
{
U u = M1();
u.Value.ToString();
}
}
union U(string, int);
""";
CreateCompilation([source, UnionAttributeSource, IUnionSource]).VerifyEmitDiagnostics();
}
Fixes #85852
Microsoft Reviewers: Open in CodeFlow