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

List patterns: Slice value is assumed to be never null #57457

Merged
merged 19 commits into from
Jan 20, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,12 @@ private static void MakeCheckNotNull(
ArrayBuilder<Tests> tests)
{
// Add a null test if needed
if (input.Type.CanContainNull())
if (input.Type.CanContainNull() &&
// The slice value is assumed to be never null
input.Source is not BoundDagSliceEvaluation)
alrz marked this conversation as resolved.
Show resolved Hide resolved
{
tests.Add(new Tests.One(new BoundDagNonNullTest(syntax, isExplicitTest, input)));
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ public PossiblyConditionalState Clone()
var outputSlot = makeDagTempSlot(type, output);
Debug.Assert(outputSlot > 0);
addToTempMap(output, outputSlot, type.Type);
this.State[outputSlot] = NullableFlowState.NotNull; // Slice value is assumed to be never null
Comment on lines 516 to +517
Copy link
Contributor Author

@alrz alrz Jan 19, 2022

Choose a reason for hiding this comment

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

❓ Should we also strip the annotation on the return type for semantic model?

I am not sure if hovering over [.. var variable] shows a nullable type (probably shouldn't?)

Copy link
Member

Choose a reason for hiding this comment

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

The var will definitely have a ?, because it always does. Theoretically, though, it should say that variable is considered not null here.

break;
}
case BoundDagAssignmentEvaluation e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ protected static void AssertEmpty(SymbolInfo info)
Assert.Equal(CandidateReason.None, info.CandidateReason);
}

protected static void VerifyDecisionDagDump<T>(Compilation comp, string expectedDecisionDag)
protected static void VerifyDecisionDagDump<T>(Compilation comp, string expectedDecisionDag, int index = 0)
where T : CSharpSyntaxNode
{
#if DEBUG
var tree = comp.SyntaxTrees.First();
var node = tree.GetRoot().DescendantNodes().OfType<T>().First();
var node = tree.GetRoot().DescendantNodes().OfType<T>().ElementAt(index);
var model = (CSharpSemanticModel)comp.GetSemanticModel(tree);
var binder = model.GetEnclosingBinder(node.SpanStart);
var decisionDag = node switch
Expand Down
Loading