Skip to content

Commit

Permalink
List patterns: Slice value is assumed to be never null (#57457)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed Jan 20, 2022
1 parent e70912b commit 305a91c
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 155 deletions.
6 changes: 5 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs
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)
{
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
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

0 comments on commit 305a91c

Please sign in to comment.