diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index d4cea5390a0f2..0acf1d7bd1f50 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -801,8 +801,12 @@ private void VisitPattern(BoundExpression expression, TypeSymbolWithAnnotations { // The result type and state of the expression carry into the variable declared by var pattern Symbol variable = declarationPattern.Variable; - _variableTypes[variable] = expressionResultType; - TrackNullableStateForAssignment(expression, expressionResultType, GetOrCreateSlot(variable), expressionResultType); + // No variable declared for discard (`i is var _`) + if ((object)variable != null) + { + _variableTypes[variable] = expressionResultType; + TrackNullableStateForAssignment(expression, expressionResultType, GetOrCreateSlot(variable), expressionResultType); + } } else { @@ -3676,7 +3680,7 @@ public override BoundNode VisitIsOperator(BoundIsOperator node) int slot = -1; var operand = node.Operand; - if (operand.Type.IsReferenceType) + if (operand.Type?.IsReferenceType == true) { slot = MakeSlot(operand); if (slot > 0)