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) 216private static readonly TypeWithState _invalidType = TypeWithState.Create(new UnsupportedMetadataTypeSymbol(), NullableFlowState.NotNull); 796var memberState = GetState(ref state, slot); 797var badState = symbolType.Type.IsPossiblyNullableReferenceTypeTypeParameter() && (annotations & FlowAnalysisAnnotations.NotNull) == 0 798? NullableFlowState.MaybeDefault 799: NullableFlowState.MaybeNull; 855SetState(ref this.State, memberSlot, type.Type.IsPossiblyNullableReferenceTypeTypeParameter() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull); 1150var parameterState = GetState(ref state, memberSlot); 1182SetState(ref this.State, memberSlot, NullableFlowState.MaybeNull); 1295var parameterState = GetState(ref state, slot); 1351var parameterState = GetState(ref stateWhen, slot); 1378private void EnforceNotNullIfNotNull(SyntaxNode? syntaxOpt, LocalState state, ImmutableArray<ParameterSymbol> parameters, ImmutableHashSet<string> inputParamNames, NullableFlowState outputState, ParameterSymbol? outputParam) 1965private NullableFlowState GetState(ref LocalState state, int slot) 1968return NullableFlowState.NotNull; 1974private void SetState(ref LocalState state, int slot, NullableFlowState value, bool useNotNullsAsDefault = false) 1996private NullableFlowState GetDefaultState(ref LocalState state, int slot) 2001return NullableFlowState.NotNull; 2031return NullableFlowState.NotNull; 2360private static bool ShouldReportNullableAssignment(TypeWithAnnotations type, NullableFlowState state) 2377case NullableFlowState.NotNull: 2379case NullableFlowState.MaybeNull: 2455valueType.State == NullableFlowState.MaybeDefault; 2637var newState = valueType.State; 2740NullableFlowState value = isDefaultValue ? NullableFlowState.MaybeNull : fieldOrPropertyType.ToTypeWithState().State; 2752NullableFlowState.NotNull; 2800/// and the new state is not <see cref="NullableFlowState.NotNull"/>, this method should be called to perform the 2804private void SetStateAndTrackForFinally(ref LocalState state, int slot, NullableFlowState newState) 2808if (newState != NullableFlowState.NotNull && NonMonotonicState.HasValue) 2893private NullableFlowState GetDefaultState(Symbol symbol) 2986var state = GetParameterState(parameterType, parameter.FlowAnalysisAnnotations).State; 3024return TypeWithState.Create(parameterType.Type, NullableFlowState.MaybeDefault); 3029return TypeWithState.Create(parameterType.Type, NullableFlowState.NotNull); 3333SetState(ref state, slot, NullableFlowState.NotNull); 3832SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 3840SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 3945NullableFlowState resultState = getResultState(node, collectionKind); 3951static NullableFlowState getResultState(BoundCollectionExpression node, CollectionExpressionTypeKind collectionKind) 3963return NullableFlowState.NotNull; 4027(int slot, NullableFlowState resultState, Func<TypeSymbol, MethodSymbol?, int>? initialStateInferenceCompletion) = 4047NullableFlowState resultState, 4076NullableFlowState resultState) 4078Debug.Assert(resultState == NullableFlowState.NotNull); 4110(int slot, NullableFlowState resultState, Func<TypeSymbol, MethodSymbol?, int>? completion) inferInitialObjectState( 4118return (-1, NullableFlowState.NotNull, inferInitialObjectStateAsContinuation(node, arguments, argumentResults, hasObjectInitializer)); 4124var resultState = NullableFlowState.NotNull; 4156resultState = NullableFlowState.MaybeNull; 4191Debug.Assert(resultState == NullableFlowState.NotNull); 4325var result = new VisitResult(objectInitializer.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull); 4514SetAnalyzedNullability(node.ImplicitReceiverOpt, new VisitResult(node.ImplicitReceiverOpt.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull)); 4572SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 4577var resultType = TypeWithState.Create(node.Type, NullableFlowState.NotNull); 4685SetResultType(node, TypeWithState.Create(anonymousType, NullableFlowState.NotNull)); 4717SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 4722SetResultType(node, TypeWithState.Create(arrayType, NullableFlowState.NotNull)); 4798var elementState = BestTypeInferrer.GetNullableState(expressionTypes); 5000NullableFlowState resultState = NullableFlowState.NotNull; 5028resultState = NullableFlowState.MaybeNull; // Delegate removal can produce null. 5031resultState = NullableFlowState.NotNull; 5558SetState(ref stateToUpdate, slot, NullableFlowState.NotNull); 5587SetState(ref state, slot, NullableFlowState.NotNull); 5612if (GetState(ref state, slot) == NullableFlowState.NotNull) 5615SetState(ref state, slot, NullableFlowState.MaybeNull); 5644SetState(ref state, childSlot, NullableFlowState.NotNull); 5723SetState(ref this.State, leftSlot, NullableFlowState.NotNull); 5778BoundNullCoalescingOperatorResultKind.NoCommonType => (node.Type, NullableFlowState.NotNull), 5783BoundNullCoalescingOperatorResultKind.RightDynamicType => (rightResultType!, NullableFlowState.NotNull), 5790(TypeSymbol ResultType, NullableFlowState LeftState) getLeftResultType(TypeSymbol leftType, TypeSymbol rightType) 5800return (rightType, NullableFlowState.NotNull); 5805return (leftType, NullableFlowState.NotNull); 5808(TypeSymbol ResultType, NullableFlowState LeftState) getResultStateWithRightType(TypeSymbol leftType, TypeSymbol rightType) 5820TypeWithState.Create(leftType, NullableFlowState.NotNull), 5831return (rightType, NullableFlowState.NotNull); 6004SetResultType(node, TypeWithState.Create(resultType, NullableFlowState.MaybeDefault)); 6059var rValueState = consequenceRValue.State.Join(alternativeRValue.State); 6167NullableFlowState resultState; 6327SetResultType(node, TypeWithState.Create(rvalueType, NullableFlowState.NotNull)); 6763private NullableFlowState LearnFromCompareExchangeMethod(in CompareExchangeInfo compareExchangeInfo) 6783return NullableFlowState.NotNull; 6793var valueFlowState = compareExchangeInfo.Results[valueIndex].RValueType.State; 6800var locationFlowState = compareExchangeInfo.Results[locationIndex].RValueType.State; 6917return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 6922return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7493SetState(ref state, memberSlot, NullableFlowState.NotNull); 7798var adjustedState = LearnFromCompareExchangeMethod(in compareExchangeInfoOpt); 7922return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7928return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 7943return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7947return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 7962return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault); 7966return TypeWithState.Create(typeWithState.Type, NullableFlowState.NotNull); 8447NullableFlowState state = GetState(ref this.State, slot); 8721SetResultType(node, TypeWithState.Create(null, NullableFlowState.NotNull)); 8728SetState(ref this.State, slot, NullableFlowState.NotNull); 8746SetResultType(node, TypeWithState.Create(tupleOpt, NullableFlowState.NotNull)); 8868SetState(ref this.State, targetFieldSlot, NullableFlowState.NotNull); 8885SetState(ref this.State, targetFieldSlot, NullableFlowState.NotNull); 9121NullableFlowState resultState = NullableFlowState.NotNull; 9153resultState = NullableFlowState.NotNull; 9177return TypeWithState.Create(targetType, NullableFlowState.NotNull); 9183resultState = NullableFlowState.NotNull; 9187resultState = NullableFlowState.NotNull; 9192resultState = NullableFlowState.NotNull; 9232resultState = NullableFlowState.NotNull; 9356resultState = NullableFlowState.NotNull; 9426static TypeWithState calculateResultType(TypeWithAnnotations targetTypeWithNullability, bool fromExplicitCast, NullableFlowState resultState, bool isSuppressed, TypeSymbol targetType) 9430resultState = NullableFlowState.NotNull; 9435resultState = targetType?.IsTypeParameterDisallowingAnnotationInCSharp8() == true ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 9442static NullableFlowState getReferenceConversionResultState(TypeWithAnnotations targetType, TypeWithState operandType) 9444var state = operandType.State; 9447case NullableFlowState.MaybeNull: 9453return NullableFlowState.MaybeDefault; 9459return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 9463case NullableFlowState.MaybeDefault: 9466return NullableFlowState.MaybeNull; 9476static NullableFlowState getBoxingConversionResultState(TypeWithAnnotations targetType, TypeWithState operandType) 9478var state = operandType.State; 9479if (state == NullableFlowState.MaybeNull) 9484return NullableFlowState.MaybeDefault; 9494return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 9504static NullableFlowState getUnboxingConversionResultState(TypeWithState operandType) 9506var state = operandType.State; 9507if (state == NullableFlowState.MaybeNull) 9509return NullableFlowState.MaybeDefault; 9514static NullableFlowState getConversionResultState(TypeWithState operandType) 9516var state = operandType.State; 9517if (state == NullableFlowState.MaybeNull) 9519return NullableFlowState.MaybeDefault; 9647var resultType = TypeWithState.Create(targetType, NullableFlowState.NotNull); 9690NullableFlowState operandState = operandType.State; 9810private TypeWithState GetLiftedReturnType(TypeWithAnnotations returnType, NullableFlowState operandState) 9814NullableFlowState state = returnType.ToTypeWithState().State.Join(operandState); 9831private TypeWithState GetLiftedReturnTypeIfNecessary(bool isLifted, TypeWithAnnotations returnType, NullableFlowState operandState) 9927var result = TypeWithState.Create(delegateType, NullableFlowState.NotNull); 10224var rvalueResult = TypeWithState.Create(node.Type, NullableFlowState.NotNull); 10644var valueBeforeNullableWrapping = TypeWithState.Create(underlyingType.Type, NullableFlowState.NotNull); 11142var state = GetState(ref this.State, slot); 11154SetState(ref this.StateWhenTrue, containingSlot, NullableFlowState.NotNull); 11372if (enumeratorReturnType.State != NullableFlowState.NotNull) 11453var state = NullableFlowState.NotNull; 11649TypeWithState.Create(node.Type, node.OperatorKind.IsLifted() ? argumentResult.State : NullableFlowState.NotNull); 11696return TypeWithState.Create(node.Type, NullableFlowState.NotNull); 11814SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 11836SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.MaybeDefault)); 11851SetState(ref this.State, slot, NullableFlowState.NotNull); 11897NullableFlowState resultState = NullableFlowState.NotNull; 11912resultState = NullableFlowState.MaybeDefault; 11950SetResultType(node, TypeWithState.Create(node.Type, node.Type?.CanContainNull() != false && node.ConstantValueOpt?.IsNull == true ? NullableFlowState.MaybeDefault : NullableFlowState.NotNull)); 12058node.IsAddition ? GetState(ref this.State, memberSlot).Meet(ResultType.State) : NullableFlowState.MaybeNull); 12175private bool ReportPossibleNullReceiverIfNeeded(TypeSymbol type, NullableFlowState state, bool checkNullableValueType, SyntaxNode syntax, out bool reportedDiagnostic) 12234SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 12249SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 12298SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull)); 12304SetResultType(node, TypeWithState.Create(type, NullableFlowState.NotNull)); 12372SetState(ref this.State, slot, NullableFlowState.NotNull); 12461Debug.Assert(ResultType is TypeWithState { Type: FunctionPointerTypeSymbol { }, State: NullableFlowState.NotNull }); 12766SetValue(Id, index, useNotNullsAsDefault ? NullableFlowState.NotNull : walker.GetDefaultState(ref this, slot)); 12770public NullableFlowState this[int slot] 12784private NullableFlowState GetValue(int id, int index) 12794private NullableFlowState GetValue(int index) 12798return NullableFlowState.NotNull; 12805var result = (_state[index], _state[index + 1]) switch 12807(false, false) => NullableFlowState.NotNull, // Should not be reachable 12808(true, false) => NullableFlowState.MaybeNull, 12809(false, true) => NullableFlowState.MaybeDefault, 12810(true, true) => NullableFlowState.NotNull 12816private void SetValue(int id, int index, NullableFlowState value) 12829private void SetValue(int index, NullableFlowState value) 12837NullableFlowState.MaybeNull => (true, false), 12838NullableFlowState.MaybeDefault => (false, true), 12839NullableFlowState.NotNull => (true, true), 12893var oldValue = oldReachable ? GetValue(i) : NullableFlowState.NotNull; 12894var newValue = oldValue.Join(other.GetValue(i)); 12919var oldValue = GetValue(i); 12920var newValue = oldValue.Meet(other.GetValue(i)); 12936var mayBeNull = GetValue(i) is NullableFlowState.MaybeNull or NullableFlowState.MaybeDefault; 12967NullableFlowState.MaybeNull => "?", 12968NullableFlowState.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)
1214static NullableFlowState getTypeArgumentState(in TypeWithAnnotations typeWithAnnotations) 1219return NullableFlowState.NotNull; 1223return type.IsNullableTypeOrTypeParameter() ? NullableFlowState.MaybeNull : NullableFlowState.NotNull; 1228return type.IsTypeParameterDisallowingAnnotationInCSharp8() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull; 1230return NullableFlowState.NotNull; 1235return NullableFlowState.NotNull; 1237NullableFlowState? result = null; 1240var constraintState = getTypeArgumentState(constraintType); 1250return result ?? NullableFlowState.MaybeNull; 1253static bool constraintTypeAllows(in TypeWithAnnotations typeWithAnnotations, NullableFlowState state) 1255if (state == NullableFlowState.NotNull) 1282return 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;