280 references to NullableFlowState
Microsoft.CodeAnalysis.CSharp (280)
Binder\Semantics\BestTypeInferrer.cs (3)
36public static NullableFlowState GetNullableState(ArrayBuilder<TypeWithState> types) 38NullableFlowState result = NullableFlowState.NotNull;
FlowAnalysis\NullableWalker_Patterns.cs (7)
466SetState(ref State, outputSlot, NullableFlowState.NotNull); 518SetState(ref this.State, outputSlot, NullableFlowState.NotNull); // Slice value is assumed to be never null 526var inputState = GetState(ref this.State, inputSlot); 631var tempState = GetState(ref this.State, tempSlot); 999receiverType: TypeWithState.Create(inputType, NullableFlowState.NotNull), 1150NullableFlowState inferredState; 1200NullableFlowState inferredState = BestTypeInferrer.GetNullableState(resultTypes);
FlowAnalysis\NullableWalker.cs (203)
145public VisitResult(TypeSymbol? type, NullableAnnotation annotation, NullableFlowState state) 235private static readonly TypeWithState _invalidType = TypeWithState.Create(new UnsupportedMetadataTypeSymbol(), NullableFlowState.NotNull); 838var memberState = GetState(ref state, slot); 839var badState = symbolType.Type.IsPossiblyNullableReferenceTypeTypeParameter() && (annotations & FlowAnalysisAnnotations.NotNull) == 0 840? NullableFlowState.MaybeDefault 841: NullableFlowState.MaybeNull; 897SetState(ref this.State, memberSlot, type.Type.IsPossiblyNullableReferenceTypeTypeParameter() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull); 1192var parameterState = GetState(ref state, memberSlot); 1224SetState(ref this.State, memberSlot, NullableFlowState.MaybeNull); 1337var parameterState = GetState(ref state, slot); 1393var parameterState = GetState(ref stateWhen, slot); 1420private void EnforceNotNullIfNotNull(SyntaxNode? syntaxOpt, LocalState state, ImmutableArray<ParameterSymbol> parameters, ImmutableHashSet<string> inputParamNames, NullableFlowState outputState, ParameterSymbol? outputParam) 2008private NullableFlowState GetState(ref LocalState state, int slot) 2011return NullableFlowState.NotNull; 2017private void SetState(ref LocalState state, int slot, NullableFlowState value, bool useNotNullsAsDefault = false) 2039private NullableFlowState GetDefaultState(ref LocalState state, int slot) 2044return NullableFlowState.NotNull; 2073var result = NullableFlowState.NotNull; 2094return NullableFlowState.NotNull; 2423private static bool ShouldReportNullableAssignment(TypeWithAnnotations type, NullableFlowState state) 2440case NullableFlowState.NotNull: 2442case NullableFlowState.MaybeNull: 2518valueType.State == NullableFlowState.MaybeDefault; 2700var newState = valueType.State; 2811NullableFlowState value = isDefaultValue ? NullableFlowState.MaybeNull : fieldOrPropertyType.ToTypeWithState().State; 2823NullableFlowState.NotNull; 2871/// and the new state is not <see cref="NullableFlowState.NotNull"/>, this method should be called to perform the 2875private void SetStateAndTrackForFinally(ref LocalState state, int slot, NullableFlowState newState) 2879if (newState != NullableFlowState.NotNull && NonMonotonicState.HasValue) 2964private NullableFlowState GetDefaultState(Symbol symbol) 3057var state = GetParameterState(parameterType, parameter.FlowAnalysisAnnotations).State; 3095return TypeWithState.Create(parameterType.Type, NullableFlowState.MaybeDefault); 3100return TypeWithState.Create(parameterType.Type, NullableFlowState.NotNull); 3403SetState(ref state, slot, NullableFlowState.NotNull); 3676placeholderResult = new VisitResult(placeholder.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull); 3927SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 3935SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 4031NullableFlowState.NotNull)); 4213NullableFlowState resultState = getResultState(node, collectionKind); 4229static NullableFlowState getResultState(BoundCollectionExpression node, CollectionExpressionTypeKind collectionKind) 4241return NullableFlowState.NotNull; 4311(int slot, NullableFlowState resultState, Func<TypeSymbol, MethodSymbol?, int>? initialStateInferenceCompletion) = 4331NullableFlowState resultState, 4360NullableFlowState resultState) 4362Debug.Assert(resultState == NullableFlowState.NotNull); 4394(int slot, NullableFlowState resultState, Func<TypeSymbol, MethodSymbol?, int>? completion) inferInitialObjectState( 4402return (-1, NullableFlowState.NotNull, inferInitialObjectStateAsContinuation(node, arguments, argumentResults, hasObjectInitializer)); 4408var resultState = NullableFlowState.NotNull; 4440resultState = NullableFlowState.MaybeNull; 4497Debug.Assert(resultState == NullableFlowState.NotNull); 4506NullableFlowState operandState; 4650var result = new VisitResult(objectInitializer.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull); 4675argumentResults = argumentResults.SetItem(0, new VisitResult(containingType, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull)); 4801firstArgumentResult = new VisitResult(containingType, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull); 4894SetAnalyzedNullability(node.ImplicitReceiverOpt, new VisitResult(node.ImplicitReceiverOpt.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull)); 4952SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 4957var resultType = TypeWithState.Create(node.Type, NullableFlowState.NotNull); 5065SetResultType(node, TypeWithState.Create(anonymousType, NullableFlowState.NotNull)); 5097SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 5102SetResultType(node, TypeWithState.Create(arrayType, NullableFlowState.NotNull)); 5178var elementState = BestTypeInferrer.GetNullableState(expressionTypes); 5380NullableFlowState resultState = NullableFlowState.NotNull; 5408resultState = NullableFlowState.MaybeNull; // Delegate removal can produce null. 5411resultState = NullableFlowState.NotNull; 6000SetState(ref stateToUpdate, slot, NullableFlowState.NotNull); 6029SetState(ref state, slot, NullableFlowState.NotNull); 6054if (GetState(ref state, slot) == NullableFlowState.NotNull) 6057SetState(ref state, slot, NullableFlowState.MaybeNull); 6086SetState(ref state, childSlot, NullableFlowState.NotNull); 6165SetState(ref this.State, leftSlot, NullableFlowState.NotNull); 6220BoundNullCoalescingOperatorResultKind.NoCommonType => (node.Type, NullableFlowState.NotNull), 6225BoundNullCoalescingOperatorResultKind.RightDynamicType => (rightResultType!, NullableFlowState.NotNull), 6232(TypeSymbol ResultType, NullableFlowState LeftState) getLeftResultType(TypeSymbol leftType, TypeSymbol rightType) 6243return (rightType, NullableFlowState.NotNull); 6249return (leftType, NullableFlowState.NotNull); 6252(TypeSymbol ResultType, NullableFlowState LeftState) getResultStateWithRightType(TypeSymbol leftType, TypeSymbol rightType) 6264TypeWithState.Create(leftType, NullableFlowState.NotNull), 6275return (rightType, NullableFlowState.NotNull); 6448SetResultType(node, TypeWithState.Create(resultType, NullableFlowState.MaybeDefault)); 6503var rValueState = consequenceRValue.State.Join(alternativeRValue.State); 6611NullableFlowState resultState; 6771SetResultType(node, TypeWithState.Create(rvalueType, NullableFlowState.NotNull)); 7309private NullableFlowState LearnFromCompareExchangeMethod(in CompareExchangeInfo compareExchangeInfo) 7329return NullableFlowState.NotNull; 7339var valueFlowState = compareExchangeInfo.Results[valueIndex].RValueType.State; 7346var locationFlowState = compareExchangeInfo.Results[locationIndex].RValueType.State; 7463return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 7468return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 8085SetState(ref state, memberSlot, NullableFlowState.NotNull); 8387var adjustedState = LearnFromCompareExchangeMethod(in compareExchangeInfoOpt); 8530return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 8536return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 8551return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 8555return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 8570return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 8574return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 9143NullableFlowState state = GetState(ref this.State, slot); 9418SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 9425SetState(ref this.State, slot, NullableFlowState.NotNull); 9443SetResultType(node, TypeWithState.Create(tupleOpt, NullableFlowState.NotNull)); 9566SetState(ref this.State, targetFieldSlot, NullableFlowState.NotNull); 9583SetState(ref this.State, targetFieldSlot, NullableFlowState.NotNull); 9878NullableFlowState resultState = NullableFlowState.NotNull; 9910resultState = NullableFlowState.NotNull; 9935return TypeWithState.Create(targetType, NullableFlowState.NotNull); 9941resultState = NullableFlowState.NotNull; 9945resultState = NullableFlowState.NotNull; 9950resultState = NullableFlowState.NotNull; 10010resultState = NullableFlowState.NotNull; 10172resultState = NullableFlowState.NotNull; 10241static TypeWithState calculateResultType(TypeWithAnnotations targetTypeWithNullability, bool fromExplicitCast, NullableFlowState resultState, bool isSuppressed, TypeSymbol targetType) 10245resultState = NullableFlowState.NotNull; 10250resultState = targetType?.IsTypeParameterDisallowingAnnotationInCSharp8() == true ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 10257static NullableFlowState getReferenceConversionResultState(TypeWithAnnotations targetType, TypeWithState operandType) 10259var state = operandType.State; 10262case NullableFlowState.MaybeNull: 10268return NullableFlowState.MaybeDefault; 10274return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 10278case NullableFlowState.MaybeDefault: 10281return NullableFlowState.MaybeNull; 10291static NullableFlowState getBoxingConversionResultState(TypeWithAnnotations targetType, TypeWithState operandType) 10293var state = operandType.State; 10294if (state == NullableFlowState.MaybeNull) 10299return NullableFlowState.MaybeDefault; 10309return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 10319static NullableFlowState getUnboxingConversionResultState(TypeWithState operandType) 10321var state = operandType.State; 10322if (state == NullableFlowState.MaybeNull) 10324return NullableFlowState.MaybeDefault; 10329static NullableFlowState getConversionResultState(TypeWithState operandType) 10331var state = operandType.State; 10332if (state == NullableFlowState.MaybeNull) 10334return NullableFlowState.MaybeDefault; 10469var resultType = TypeWithState.Create(targetType, NullableFlowState.NotNull); 10512NullableFlowState operandState = operandType.State; 10577private TypeWithState GetConversionReturnTypeWithState(MethodSymbol method, bool isLiftedConversion, NullableFlowState operandState) 10621var resultType = TypeWithState.Create(targetTypeWithNullability.Type, NullableFlowState.NotNull); 10710unionTypeWithState = TypeWithState.Create(toType, NullableFlowState.NotNull); 10804private TypeWithState GetLiftedReturnType(TypeWithAnnotations returnType, NullableFlowState operandState) 10808NullableFlowState state = returnType.ToTypeWithState().State.Join(operandState); 10825private TypeWithState GetLiftedReturnTypeIfNecessary(bool isLifted, TypeWithAnnotations returnType, NullableFlowState operandState) 10921var result = TypeWithState.Create(delegateType, NullableFlowState.NotNull); 11218var rvalueResult = TypeWithState.Create(node.Type, NullableFlowState.NotNull); 11636var valueBeforeNullableWrapping = TypeWithState.Create(underlyingType.Type, NullableFlowState.NotNull); 11769SetResultType(node, TypeWithState.Create(receiverType.Type, NullableFlowState.NotNull)); 11793SetResultType(node, TypeWithState.Create(opType.Type, NullableFlowState.NotNull)); 11962SetResultType(node, TypeWithState.Create(receiverType.Type, NullableFlowState.NotNull)); 11990SetResultType(node, TypeWithState.Create(opType.Type, NullableFlowState.NotNull)); 12349var state = GetState(ref this.State, slot); 12371SetState(ref this.StateWhenTrue, slotToSet, NullableFlowState.NotNull); 12593if (enumeratorReturnType.State != NullableFlowState.NotNull) 12664var state = NullableFlowState.NotNull; 12868TypeWithState.Create(node.Type, node.OperatorKind.IsLifted() ? argumentResult.State : NullableFlowState.NotNull); 13134SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 13156SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.MaybeDefault)); 13171SetState(ref this.State, slot, NullableFlowState.NotNull); 13217NullableFlowState resultState = NullableFlowState.NotNull; 13232resultState = NullableFlowState.MaybeDefault; 13270SetResultType(node, TypeWithState.Create(node.Type, node.Type?.CanContainNull() != false && node.ConstantValueOpt?.IsNull == true ? NullableFlowState.MaybeDefault : NullableFlowState.NotNull)); 13378node.IsAddition ? GetState(ref this.State, memberSlot).Meet(ResultType.State) : NullableFlowState.MaybeNull); 13495private bool ReportPossibleNullReceiverIfNeeded(TypeSymbol type, NullableFlowState state, bool checkNullableValueType, SyntaxNode syntax, out bool reportedDiagnostic) 13554SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 13569SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 13618SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 13624SetResultType(node, TypeWithState.Create(type, NullableFlowState.NotNull)); 13692SetState(ref this.State, slot, NullableFlowState.NotNull); 13834Debug.Assert(ResultType is TypeWithState { Type: FunctionPointerTypeSymbol { }, State: NullableFlowState.NotNull }); 14140SetValue(Id, index, useNotNullsAsDefault ? NullableFlowState.NotNull : walker.GetDefaultState(ref this, slot)); 14144public NullableFlowState this[int slot] 14158private NullableFlowState GetValue(int id, int index) 14168private NullableFlowState GetValue(int index) 14172return NullableFlowState.NotNull; 14179var result = (_state[index], _state[index + 1]) switch 14181(false, false) => NullableFlowState.NotNull, // Should not be reachable 14182(true, false) => NullableFlowState.MaybeNull, 14183(false, true) => NullableFlowState.MaybeDefault, 14184(true, true) => NullableFlowState.NotNull 14190private void SetValue(int id, int index, NullableFlowState value) 14203private void SetValue(int index, NullableFlowState value) 14211NullableFlowState.MaybeNull => (true, false), 14212NullableFlowState.MaybeDefault => (false, true), 14213NullableFlowState.NotNull => (true, true), 14267var oldValue = oldReachable ? GetValue(i) : NullableFlowState.NotNull; 14268var newValue = oldValue.Join(other.GetValue(i)); 14293var oldValue = GetValue(i); 14294var newValue = oldValue.Meet(other.GetValue(i)); 14310var mayBeNull = GetValue(i) is NullableFlowState.MaybeNull or NullableFlowState.MaybeDefault; 14341NullableFlowState.MaybeNull => "?", 14342NullableFlowState.MaybeDefault => "??",
Symbols\ConstraintsHelper.cs (14)
1226static NullableFlowState getTypeArgumentState(in TypeWithAnnotations typeWithAnnotations) 1231return NullableFlowState.NotNull; 1235return type.IsNullableTypeOrTypeParameter() ? NullableFlowState.MaybeNull : NullableFlowState.NotNull; 1240return type.IsTypeParameterDisallowingAnnotationInCSharp8() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 1242return NullableFlowState.NotNull; 1247return NullableFlowState.NotNull; 1249NullableFlowState? result = null; 1252var constraintState = getTypeArgumentState(constraintType); 1262return result ?? NullableFlowState.MaybeNull; 1265static bool constraintTypeAllows(in TypeWithAnnotations typeWithAnnotations, NullableFlowState state) 1267if (state == NullableFlowState.NotNull) 1294return state == NullableFlowState.MaybeNull;
Symbols\NullableAnnotationExtensions.cs (1)
104var flowState = TypeWithAnnotations.Create(type, annotation).ToTypeWithState().State;
Symbols\NullableFlowState.cs (1)
11/// When in doubt we conservatively use <see cref="NullableFlowState.NotNull"/>
Symbols\NullableFlowStateExtensions.cs (20)
13public static bool MayBeNull(this NullableFlowState state) => state != NullableFlowState.NotNull; 15public static bool IsNotNull(this NullableFlowState state) => state == NullableFlowState.NotNull; 19/// The result is <see cref="NullableFlowState.MaybeNull"/> if either operand is that. 21public static NullableFlowState Join(this NullableFlowState a, NullableFlowState b) => (a > b) ? a : b; 25/// The result is <see cref="NullableFlowState.NotNull"/> if either operand is that. 27public static NullableFlowState Meet(this NullableFlowState a, NullableFlowState b) => (a < b) ? a : b; 29internal static CodeAnalysis.NullableFlowState ToPublicFlowState(this CSharp.NullableFlowState nullableFlowState) => 32CSharp.NullableFlowState.NotNull => CodeAnalysis.NullableFlowState.NotNull, 33CSharp.NullableFlowState.MaybeNull => CodeAnalysis.NullableFlowState.MaybeNull, 34CSharp.NullableFlowState.MaybeDefault => CodeAnalysis.NullableFlowState.MaybeNull, 39public static CSharp.NullableFlowState ToInternalFlowState(this CodeAnalysis.NullableFlowState flowState) => 42CodeAnalysis.NullableFlowState.None => CSharp.NullableFlowState.NotNull, 43CodeAnalysis.NullableFlowState.NotNull => CSharp.NullableFlowState.NotNull, 44CodeAnalysis.NullableFlowState.MaybeNull => CSharp.NullableFlowState.MaybeNull,
Symbols\TypeWithAnnotations.cs (11)
813static NullableFlowState getFlowState(TypeSymbol type, NullableAnnotation annotation) 817return annotation.IsAnnotated() ? NullableFlowState.MaybeDefault : NullableFlowState.NotNull; 821return annotation switch { NullableAnnotation.Annotated => NullableFlowState.MaybeDefault, NullableAnnotation.NotAnnotated => NullableFlowState.MaybeNull, _ => NullableFlowState.NotNull }; 825return annotation switch { NullableAnnotation.Annotated => NullableFlowState.MaybeDefault, _ => NullableFlowState.NotNull }; 829return NullableFlowState.MaybeNull; 831return annotation switch { NullableAnnotation.Annotated => NullableFlowState.MaybeNull, _ => NullableFlowState.NotNull };
Symbols\TypeWithState.cs (20)
17public readonly NullableFlowState State; 20public bool MayBeNull => State == NullableFlowState.MaybeNull; 21public bool IsNotNull => State == NullableFlowState.NotNull; 25return Create(type, NullableFlowState.MaybeDefault); 28public static TypeWithState Create(TypeSymbol? type, NullableFlowState defaultState) 30if (defaultState == NullableFlowState.MaybeDefault && 36var state = defaultState != NullableFlowState.NotNull && type?.CanContainNull() != false ? NullableFlowState.MaybeNull : NullableFlowState.NotNull; 45NullableFlowState state; 50state = NullableFlowState.MaybeDefault; 54state = NullableFlowState.NotNull; 63state = NullableFlowState.NotNull; 69private TypeWithState(TypeSymbol? type, NullableFlowState state) 71Debug.Assert(state == NullableFlowState.NotNull || type?.CanContainNull() != false); 72Debug.Assert(state != NullableFlowState.MaybeDefault || type is null || type.IsTypeParameterDisallowingAnnotationInCSharp8()); 81public TypeWithState WithNotNullState() => new TypeWithState(Type, NullableFlowState.NotNull); 83public TypeWithState WithSuppression(bool suppress) => suppress ? new TypeWithState(Type, NullableFlowState.NotNull) : this; 90return (State == NullableFlowState.MaybeDefault || asAnnotatedType) ? type.SetIsAnnotated(compilation) : type;