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