265 references to NullableFlowState
Microsoft.CodeAnalysis.CSharp (265)
Binder\Semantics\BestTypeInferrer.cs (3)
36public static NullableFlowState GetNullableState(ArrayBuilder<TypeWithState> types) 38NullableFlowState result = NullableFlowState.NotNull;
FlowAnalysis\NullableWalker.cs (190)
126public VisitResult(TypeSymbol? type, NullableAnnotation annotation, NullableFlowState state) 210private static readonly TypeWithState _invalidType = TypeWithState.Create(new UnsupportedMetadataTypeSymbol(), NullableFlowState.NotNull); 783var memberState = GetState(ref state, slot); 784var badState = symbolType.Type.IsPossiblyNullableReferenceTypeTypeParameter() && (annotations & FlowAnalysisAnnotations.NotNull) == 0 785? NullableFlowState.MaybeDefault 786: NullableFlowState.MaybeNull; 842SetState(ref this.State, memberSlot, type.Type.IsPossiblyNullableReferenceTypeTypeParameter() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull); 1137var parameterState = GetState(ref state, memberSlot); 1169SetState(ref this.State, memberSlot, NullableFlowState.MaybeNull); 1269var parameterState = GetState(ref state, slot); 1325var parameterState = GetState(ref stateWhen, slot); 1352private void EnforceNotNullIfNotNull(SyntaxNode? syntaxOpt, LocalState state, ImmutableArray<ParameterSymbol> parameters, ImmutableHashSet<string> inputParamNames, NullableFlowState outputState, ParameterSymbol? outputParam) 1928private NullableFlowState GetState(ref LocalState state, int slot) 1931return NullableFlowState.NotNull; 1937private void SetState(ref LocalState state, int slot, NullableFlowState value, bool useNotNullsAsDefault = false) 1959private NullableFlowState GetDefaultState(ref LocalState state, int slot) 1964return NullableFlowState.NotNull; 1994return NullableFlowState.NotNull; 2323private static bool ShouldReportNullableAssignment(TypeWithAnnotations type, NullableFlowState state) 2340case NullableFlowState.NotNull: 2342case NullableFlowState.MaybeNull: 2418valueType.State == NullableFlowState.MaybeDefault; 2600var newState = valueType.State; 2700NullableFlowState value = isDefaultValue ? NullableFlowState.MaybeNull : fieldOrPropertyType.ToTypeWithState().State; 2712NullableFlowState.NotNull; 2744/// and the new state is not <see cref="NullableFlowState.NotNull"/>, this method should be called to perform the 2748private void SetStateAndTrackForFinally(ref LocalState state, int slot, NullableFlowState newState) 2752if (newState != NullableFlowState.NotNull && NonMonotonicState.HasValue) 2799private NullableFlowState GetDefaultState(Symbol symbol) 2890var state = GetParameterState(parameterType, parameter.FlowAnalysisAnnotations).State; 2928return TypeWithState.Create(parameterType.Type, NullableFlowState.MaybeDefault); 2933return TypeWithState.Create(parameterType.Type, NullableFlowState.NotNull); 3236SetState(ref state, slot, NullableFlowState.NotNull); 3735SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 3743SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 3848NullableFlowState resultState = getResultState(node, collectionKind); 3854static NullableFlowState getResultState(BoundCollectionExpression node, CollectionExpressionTypeKind collectionKind) 3866return NullableFlowState.NotNull; 3929(int slot, NullableFlowState resultState, Func<TypeSymbol, MethodSymbol?, int>? initialStateInferenceCompletion) = inferInitialObjectState(node, type, constructor, arguments, argumentResults, isTargetTyped); 3949NullableFlowState resultState, 3978NullableFlowState resultState) 3980Debug.Assert(resultState == NullableFlowState.NotNull); 4012(int slot, NullableFlowState resultState, Func<TypeSymbol, MethodSymbol?, int>? completion) inferInitialObjectState( 4019return (-1, NullableFlowState.NotNull, inferInitialObjectStateAsContinuation(node, arguments, argumentResults)); 4027var resultState = NullableFlowState.NotNull; 4057resultState = NullableFlowState.MaybeNull; 4091Debug.Assert(resultState == NullableFlowState.NotNull); 4225var result = new VisitResult(objectInitializer.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull); 4414SetAnalyzedNullability(node.ImplicitReceiverOpt, new VisitResult(node.ImplicitReceiverOpt.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull)); 4471SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 4476var resultType = TypeWithState.Create(node.Type, NullableFlowState.NotNull); 4584SetResultType(node, TypeWithState.Create(anonymousType, NullableFlowState.NotNull)); 4616SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 4621SetResultType(node, TypeWithState.Create(arrayType, NullableFlowState.NotNull)); 4697var elementState = BestTypeInferrer.GetNullableState(expressionTypes); 4898NullableFlowState resultState = NullableFlowState.NotNull; 4926resultState = NullableFlowState.MaybeNull; // Delegate removal can produce null. 4929resultState = NullableFlowState.NotNull; 5461SetState(ref stateToUpdate, slot, NullableFlowState.NotNull); 5490SetState(ref state, slot, NullableFlowState.NotNull); 5515if (GetState(ref state, slot) == NullableFlowState.NotNull) 5518SetState(ref state, slot, NullableFlowState.MaybeNull); 5547SetState(ref state, childSlot, NullableFlowState.NotNull); 5626SetState(ref this.State, leftSlot, NullableFlowState.NotNull); 5681BoundNullCoalescingOperatorResultKind.NoCommonType => (node.Type, NullableFlowState.NotNull), 5686BoundNullCoalescingOperatorResultKind.RightDynamicType => (rightResultType!, NullableFlowState.NotNull), 5693(TypeSymbol ResultType, NullableFlowState LeftState) getLeftResultType(TypeSymbol leftType, TypeSymbol rightType) 5703return (rightType, NullableFlowState.NotNull); 5708return (leftType, NullableFlowState.NotNull); 5711(TypeSymbol ResultType, NullableFlowState LeftState) getResultStateWithRightType(TypeSymbol leftType, TypeSymbol rightType) 5723TypeWithState.Create(leftType, NullableFlowState.NotNull), 5734return (rightType, NullableFlowState.NotNull); 5906SetResultType(node, TypeWithState.Create(resultType, NullableFlowState.MaybeDefault)); 5961var rValueState = consequenceRValue.State.Join(alternativeRValue.State); 6069NullableFlowState resultState; 6229SetResultType(node, TypeWithState.Create(rvalueType, NullableFlowState.NotNull)); 6558private NullableFlowState LearnFromCompareExchangeMethod(in CompareExchangeInfo compareExchangeInfo) 6578return NullableFlowState.NotNull; 6588var valueFlowState = compareExchangeInfo.Results[valueIndex].RValueType.State; 6595var locationFlowState = compareExchangeInfo.Results[locationIndex].RValueType.State; 6707return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 6712return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7266SetState(ref state, memberSlot, NullableFlowState.NotNull); 7571var adjustedState = LearnFromCompareExchangeMethod(in compareExchangeInfoOpt); 7695return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7701return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 7716return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7720return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 7735return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7739return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 8213NullableFlowState state = GetState(ref this.State, slot); 8486SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 8493SetState(ref this.State, slot, NullableFlowState.NotNull); 8511SetResultType(node, TypeWithState.Create(tupleOpt, NullableFlowState.NotNull)); 8633SetState(ref this.State, targetFieldSlot, NullableFlowState.NotNull); 8650SetState(ref this.State, targetFieldSlot, NullableFlowState.NotNull); 8886NullableFlowState resultState = NullableFlowState.NotNull; 8918resultState = NullableFlowState.NotNull; 8942return TypeWithState.Create(targetType, NullableFlowState.NotNull); 8948resultState = NullableFlowState.NotNull; 8952resultState = NullableFlowState.NotNull; 8957resultState = NullableFlowState.NotNull; 8997resultState = NullableFlowState.NotNull; 9121resultState = NullableFlowState.NotNull; 9191static TypeWithState calculateResultType(TypeWithAnnotations targetTypeWithNullability, bool fromExplicitCast, NullableFlowState resultState, bool isSuppressed, TypeSymbol targetType) 9195resultState = NullableFlowState.NotNull; 9200resultState = targetType?.IsTypeParameterDisallowingAnnotationInCSharp8() == true ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 9207static NullableFlowState getReferenceConversionResultState(TypeWithAnnotations targetType, TypeWithState operandType) 9209var state = operandType.State; 9212case NullableFlowState.MaybeNull: 9218return NullableFlowState.MaybeDefault; 9224return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 9228case NullableFlowState.MaybeDefault: 9231return NullableFlowState.MaybeNull; 9241static NullableFlowState getBoxingConversionResultState(TypeWithAnnotations targetType, TypeWithState operandType) 9243var state = operandType.State; 9244if (state == NullableFlowState.MaybeNull) 9249return NullableFlowState.MaybeDefault; 9259return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 9269static NullableFlowState getUnboxingConversionResultState(TypeWithState operandType) 9271var state = operandType.State; 9272if (state == NullableFlowState.MaybeNull) 9274return NullableFlowState.MaybeDefault; 9279static NullableFlowState getConversionResultState(TypeWithState operandType) 9281var state = operandType.State; 9282if (state == NullableFlowState.MaybeNull) 9284return NullableFlowState.MaybeDefault; 9412var resultType = TypeWithState.Create(targetType, NullableFlowState.NotNull); 9455NullableFlowState operandState = operandType.State; 9575private TypeWithState GetLiftedReturnType(TypeWithAnnotations returnType, NullableFlowState operandState) 9579NullableFlowState state = returnType.ToTypeWithState().State.Join(operandState); 9596private TypeWithState GetLiftedReturnTypeIfNecessary(bool isLifted, TypeWithAnnotations returnType, NullableFlowState operandState) 9692var result = TypeWithState.Create(delegateType, NullableFlowState.NotNull); 9977var rvalueResult = TypeWithState.Create(node.Type, NullableFlowState.NotNull); 10380var valueBeforeNullableWrapping = TypeWithState.Create(underlyingType.Type, NullableFlowState.NotNull); 10844var state = GetState(ref this.State, slot); 10856SetState(ref this.StateWhenTrue, containingSlot, NullableFlowState.NotNull); 11074if (enumeratorReturnType.State != NullableFlowState.NotNull) 11155var state = NullableFlowState.NotNull; 11351TypeWithState.Create(node.Type, node.OperatorKind.IsLifted() ? argumentResult.State : NullableFlowState.NotNull); 11398return TypeWithState.Create(node.Type, NullableFlowState.NotNull); 11516SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 11538SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.MaybeDefault)); 11553SetState(ref this.State, slot, NullableFlowState.NotNull); 11599NullableFlowState resultState = NullableFlowState.NotNull; 11614resultState = NullableFlowState.MaybeDefault; 11652SetResultType(node, TypeWithState.Create(node.Type, node.Type?.CanContainNull() != false && node.ConstantValueOpt?.IsNull == true ? NullableFlowState.MaybeDefault : NullableFlowState.NotNull)); 11760node.IsAddition ? GetState(ref this.State, memberSlot).Meet(ResultType.State) : NullableFlowState.MaybeNull); 11877private bool ReportPossibleNullReceiverIfNeeded(TypeSymbol type, NullableFlowState state, bool checkNullableValueType, SyntaxNode syntax, out bool reportedDiagnostic) 11936SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 11951SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 12000SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 12006SetResultType(node, TypeWithState.Create(type, NullableFlowState.NotNull)); 12074SetState(ref this.State, slot, NullableFlowState.NotNull); 12163Debug.Assert(ResultType is TypeWithState { Type: FunctionPointerTypeSymbol { }, State: NullableFlowState.NotNull }); 12468SetValue(Id, index, useNotNullsAsDefault ? NullableFlowState.NotNull : walker.GetDefaultState(ref this, slot)); 12472public NullableFlowState this[int slot] 12486private NullableFlowState GetValue(int id, int index) 12496private NullableFlowState GetValue(int index) 12500return NullableFlowState.NotNull; 12507var result = (_state[index], _state[index + 1]) switch 12509(false, false) => NullableFlowState.NotNull, // Should not be reachable 12510(true, false) => NullableFlowState.MaybeNull, 12511(false, true) => NullableFlowState.MaybeDefault, 12512(true, true) => NullableFlowState.NotNull 12518private void SetValue(int id, int index, NullableFlowState value) 12531private void SetValue(int index, NullableFlowState value) 12539NullableFlowState.MaybeNull => (true, false), 12540NullableFlowState.MaybeDefault => (false, true), 12541NullableFlowState.NotNull => (true, true), 12595var oldValue = oldReachable ? GetValue(i) : NullableFlowState.NotNull; 12596var newValue = oldValue.Join(other.GetValue(i)); 12621var oldValue = GetValue(i); 12622var newValue = oldValue.Meet(other.GetValue(i)); 12638var mayBeNull = GetValue(i) is NullableFlowState.MaybeNull or NullableFlowState.MaybeDefault; 12669NullableFlowState.MaybeNull => "?", 12670NullableFlowState.MaybeDefault => "??",
FlowAnalysis\NullableWalker_Patterns.cs (5)
481SetState(ref State, outputSlot, NullableFlowState.NotNull); 577SetState(ref this.State, outputSlot, NullableFlowState.NotNull); // Slice value is assumed to be never null 680var tempState = GetState(ref this.State, tempSlot); 956NullableFlowState inferredState; 1006NullableFlowState inferredState = BestTypeInferrer.GetNullableState(resultTypes);
Symbols\ConstraintsHelper.cs (14)
1199static NullableFlowState getTypeArgumentState(in TypeWithAnnotations typeWithAnnotations) 1204return NullableFlowState.NotNull; 1208return type.IsNullableTypeOrTypeParameter() ? NullableFlowState.MaybeNull : NullableFlowState.NotNull; 1213return type.IsTypeParameterDisallowingAnnotationInCSharp8() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 1215return NullableFlowState.NotNull; 1220return NullableFlowState.NotNull; 1222NullableFlowState? result = null; 1225var constraintState = getTypeArgumentState(constraintType); 1235return result ?? NullableFlowState.MaybeNull; 1238static bool constraintTypeAllows(in TypeWithAnnotations typeWithAnnotations, NullableFlowState state) 1240if (state == NullableFlowState.NotNull) 1267return 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;