Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsplit NullableWalker after out argument #69511

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6682,6 +6682,7 @@ private VisitArgumentResult VisitArgumentEvaluate(BoundExpression argument, RefK
// As far as we can tell, there is no scenario relevant to nullability analysis
// where splitting an L-value (for instance with a ref conditional) would affect the result.
Comment on lines 6682 to 6683
Copy link
Member

@Youssef1313 Youssef1313 Aug 16, 2023

Choose a reason for hiding this comment

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

@jcouv @jjonescz Is this comment outdated now? Nope, misread it. Sorry.

Visit(argument);
Unsplit();

// We'll want to use the l-value type, rather than the result type, for method re-inference
UseLvalueOnly(argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26944,6 +26944,41 @@ static void M5<T>(T? t5) where T : struct
);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/67816")]
public void MaybeNullWhenTrue_OutParameter_Conditional()
{
var source = """
#nullable enable
using System.Diagnostics.CodeAnalysis;

internal class C
{
private static bool M([NotNullWhen(true)] out object? o)
{
}

public C()
{
if (!M(p => p.A(), out
"".B() is null
))
{
}
}
}
""";
CreateCompilation(new[] { source, NotNullWhenAttributeDefinition }).VerifyDiagnostics(
// (6,25): error CS0177: The out parameter 'o' must be assigned to before control leaves the current method
// private static bool M([NotNullWhen(true)] out object? o)
Diagnostic(ErrorCode.ERR_ParamUnassigned, "M").WithArguments("o").WithLocation(6, 25),
// (6,25): error CS0161: 'C.M(out object?)': not all code paths return a value
// private static bool M([NotNullWhen(true)] out object? o)
Diagnostic(ErrorCode.ERR_ReturnExpected, "M").WithArguments("C.M(out object?)").WithLocation(6, 25),
// (13,16): error CS1061: 'string' does not contain a definition for 'B' and no accessible extension method 'B' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
// "".B() is null
Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "B").WithArguments("string", "B").WithLocation(13, 16));
}

[Fact]
public void MaybeNullWhenTrue_FromMetadata()
{
Expand Down