FlowAnalysis\NullableWalker.cs (32)
126public VisitResult(TypeSymbol? type, NullableAnnotation annotation, NullableFlowState state)
2272case NullableAnnotation.Oblivious:
2273case NullableAnnotation.Annotated:
4164var result = new VisitResult(objectInitializer.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull);
4353SetAnalyzedNullability(node.ImplicitReceiverOpt, new VisitResult(node.ImplicitReceiverOpt.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull));
4468return GetOrCreatePlaceholderSlot(node, TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated));
5568targetType = TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated);
5899var lValueAnnotation = consequenceLValue.NullableAnnotation.EnsureCompatible(alternativeLValue.NullableAnnotation);
7894private static NullableAnnotation GetNullableAnnotation(BoundExpression expr)
7901return expr.ConstantValueOpt == ConstantValue.NotAvailable || !expr.ConstantValueOpt.IsNull || expr.IsSuppressed ? NullableAnnotation.NotAnnotated : NullableAnnotation.Annotated;
7909return NullableAnnotation.NotAnnotated;
7912return NullableAnnotation.Oblivious;
7994return new BoundExpressionWithNullability(argument.Syntax, argument, NullableAnnotation.Oblivious, type: null);
9164dependsOnTypeParameter(typeParameter1, (TypeParameterSymbol)targetType.Type, NullableAnnotation.NotAnnotated, out var annotation))
9166return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull;
9197bool dependsOn = dependsOnTypeParameter(typeParameter1, typeParameter2, NullableAnnotation.NotAnnotated, out var annotation);
9201return (annotation == NullableAnnotation.Annotated) ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull;
9234static bool dependsOnTypeParameter(TypeParameterSymbol typeParameter1, TypeParameterSymbol typeParameter2, NullableAnnotation typeParameter1Annotation, out NullableAnnotation annotation)
9242var combinedAnnotation = NullableAnnotation.Annotated;
9246dependsOnTypeParameter(constraintTypeParameter, typeParameter2, constraintType.NullableAnnotation, out var constraintAnnotation))
9733var argTypeWithAnnotations = TypeWithAnnotations.Create(argType, NullableAnnotation.NotAnnotated);
9920var lvalueResult = TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated);
10187placeholderArgs.Add(new BoundExpressionWithNullability(variables[i].Expression.Syntax, variables[i].Expression, NullableAnnotation.Oblivious, conversion.DeconstructionInfo.OutputPlaceholders[i].Type));
10990TypeWithAnnotations.Create(enumeratorInfoOpt.ElementType, NullableAnnotation.NotAnnotated).ToTypeWithState();
11677var result = TypeWithAnnotations.Create(node.Type, NullableAnnotation.Oblivious);
11783var result = TypeWithAnnotations.Create(node.Type, NullableAnnotation.Oblivious);
11954var result = TypeWithAnnotations.Create(node.Type, node.IsInferred ? NullableAnnotation.Annotated : node.NullableAnnotation);
Generated\BoundNodes.xml.Generated.cs (10)
1544public BoundRefValueOperator(SyntaxNode syntax, NullableAnnotation nullableAnnotation, BoundExpression operand, TypeSymbol type, bool hasErrors = false)
1556public NullableAnnotation NullableAnnotation { get; }
1562public BoundRefValueOperator Update(NullableAnnotation nullableAnnotation, BoundExpression operand, TypeSymbol type)
8527public BoundDiscardExpression(SyntaxNode syntax, NullableAnnotation nullableAnnotation, bool isInferred, TypeSymbol? type, bool hasErrors)
8534public BoundDiscardExpression(SyntaxNode syntax, NullableAnnotation nullableAnnotation, bool isInferred, TypeSymbol? type)
8542public NullableAnnotation NullableAnnotation { get; }
8548public BoundDiscardExpression Update(NullableAnnotation nullableAnnotation, bool isInferred, TypeSymbol? type)
8760public BoundExpressionWithNullability(SyntaxNode syntax, BoundExpression expression, NullableAnnotation nullableAnnotation, TypeSymbol? type, bool hasErrors = false)
8772public NullableAnnotation NullableAnnotation { get; }
8777public BoundExpressionWithNullability Update(BoundExpression expression, NullableAnnotation nullableAnnotation, TypeSymbol? type)
Symbols\NullableAnnotationExtensions.cs (44)
16public static bool IsAnnotated(this NullableAnnotation annotation) => annotation == NullableAnnotation.Annotated;
18public static bool IsNotAnnotated(this NullableAnnotation annotation) => annotation == NullableAnnotation.NotAnnotated;
20public static bool IsOblivious(this NullableAnnotation annotation) => annotation == NullableAnnotation.Oblivious;
26public static NullableAnnotation Join(this NullableAnnotation a, NullableAnnotation b)
28Debug.Assert(a != NullableAnnotation.Ignored);
29Debug.Assert(b != NullableAnnotation.Ignored);
37public static NullableAnnotation Meet(this NullableAnnotation a, NullableAnnotation b)
39Debug.Assert(a != NullableAnnotation.Ignored);
40Debug.Assert(b != NullableAnnotation.Ignored);
48public static NullableAnnotation EnsureCompatible(this NullableAnnotation a, NullableAnnotation b)
50Debug.Assert(a != NullableAnnotation.Ignored);
51Debug.Assert(b != NullableAnnotation.Ignored);
54(NullableAnnotation.Oblivious, _) => b,
55(_, NullableAnnotation.Oblivious) => a,
63public static NullableAnnotation MergeNullableAnnotation(this NullableAnnotation a, NullableAnnotation b, VarianceKind variance)
65Debug.Assert(a != NullableAnnotation.Ignored);
66Debug.Assert(b != NullableAnnotation.Ignored);
77/// The attribute (metadata) representation of <see cref="NullableAnnotation.NotAnnotated"/>.
82/// The attribute (metadata) representation of <see cref="NullableAnnotation.Annotated"/>.
87/// The attribute (metadata) representation of <see cref="NullableAnnotation.Oblivious"/>.
98CSharp.NullableAnnotation internalAnnotation = annotation.ToInternalAnnotation();
102internal static NullabilityInfo ToNullabilityInfo(this NullableAnnotation annotation, TypeSymbol type)
126internal static CodeAnalysis.NullableAnnotation ToPublicAnnotation(TypeSymbol? type, NullableAnnotation annotation)
128Debug.Assert(annotation != NullableAnnotation.Ignored);
131NullableAnnotation.Annotated => CodeAnalysis.NullableAnnotation.Annotated,
132NullableAnnotation.NotAnnotated => CodeAnalysis.NullableAnnotation.NotAnnotated,
137NullableAnnotation.Oblivious when type?.IsValueType == true => CodeAnalysis.NullableAnnotation.NotAnnotated,
138NullableAnnotation.Oblivious => CodeAnalysis.NullableAnnotation.None,
140NullableAnnotation.Ignored => CodeAnalysis.NullableAnnotation.None,
148internal static CSharp.NullableAnnotation ToInternalAnnotation(this CodeAnalysis.NullableAnnotation annotation) =>
151CodeAnalysis.NullableAnnotation.None => CSharp.NullableAnnotation.Oblivious,
152CodeAnalysis.NullableAnnotation.NotAnnotated => CSharp.NullableAnnotation.NotAnnotated,
153CodeAnalysis.NullableAnnotation.Annotated => CSharp.NullableAnnotation.Annotated,
Symbols\TypeWithAnnotations.cs (73)
51public readonly NullableAnnotation DefaultNullableAnnotation;
53private TypeWithAnnotations(TypeSymbol defaultType, NullableAnnotation defaultAnnotation, Extensions extensions)
55Debug.Assert(defaultType?.IsNullableType() != true || defaultAnnotation == NullableAnnotation.Annotated);
82return Create(typeSymbol, nullableAnnotation: isAnnotated ? NullableAnnotation.Annotated : isNullableEnabled ? NullableAnnotation.NotAnnotated : NullableAnnotation.Oblivious);
85internal static TypeWithAnnotations Create(TypeSymbol typeSymbol, NullableAnnotation nullableAnnotation = NullableAnnotation.Oblivious, ImmutableArray<CustomModifier> customModifiers = default)
92Debug.Assert(nullableAnnotation != NullableAnnotation.Ignored || typeSymbol.IsTypeParameter());
95case NullableAnnotation.Oblivious:
96case NullableAnnotation.NotAnnotated:
100nullableAnnotation = NullableAnnotation.Annotated;
115return Create(Type, NullableAnnotation.Annotated, CustomModifiers);
125return Create(Type, NullableAnnotation.NotAnnotated, CustomModifiers);
129internal NullableAnnotation GetValueNullableAnnotation()
138return NullableAnnotation.Annotated;
143return NullableAnnotation.Annotated;
155case NullableAnnotation.Oblivious:
156case NullableAnnotation.Annotated:
159case NullableAnnotation.NotAnnotated:
168private static TypeWithAnnotations CreateNonLazyType(TypeSymbol typeSymbol, NullableAnnotation nullableAnnotation, ImmutableArray<CustomModifier> customModifiers)
175return new TypeWithAnnotations(defaultType: underlying.DefaultType, defaultAnnotation: NullableAnnotation.Annotated, new LazyNullableTypeParameter(compilation, underlying));
180return new TypeWithAnnotations(defaultType: substitutedTypeSymbol, defaultAnnotation: NullableAnnotation.Ignored, new LazySubstitutedType(customModifiers, typeParameter));
204return CreateNonLazyType(typeSymbol, NullableAnnotation.Annotated, this.CustomModifiers);
244NullableAnnotation nullableAnnotation = this.NullableAnnotation.MergeNullableAnnotation(other.NullableAnnotation, variance);
255public NullableAnnotation NullableAnnotation => _extensions?.GetResolvedAnnotation(DefaultNullableAnnotation) ?? default;
364var thisAnnotation = NullableAnnotation;
365var otherAnnotation = other.NullableAnnotation;
442Debug.Assert(NullableAnnotation != NullableAnnotation.Ignored);
452Debug.Assert(NullableAnnotation != NullableAnnotation.Ignored);
473else if (Is((TypeParameterSymbol)typeSymbol) && newTypeWithModifiers.NullableAnnotation != NullableAnnotation.Ignored)
483NullableAnnotation newAnnotation;
484Debug.Assert(newTypeWithModifiers.Type is not IndexedTypeParameterSymbol || newTypeWithModifiers.NullableAnnotation == NullableAnnotation.Ignored);
488newAnnotation = NullableAnnotation.Annotated;
490else if (newTypeWithModifiers.NullableAnnotation == NullableAnnotation.Ignored)
494else if (NullableAnnotation != NullableAnnotation.Oblivious)
496Debug.Assert(NullableAnnotation == NullableAnnotation.NotAnnotated);
497if (newTypeWithModifiers.NullableAnnotation == NullableAnnotation.Oblivious)
505newAnnotation = NullableAnnotation.NotAnnotated;
518Debug.Assert(newTypeWithModifiers.NullableAnnotation is NullableAnnotation.NotAnnotated);
519newAnnotation = NullableAnnotation.NotAnnotated;
522else if (newTypeWithModifiers.NullableAnnotation != NullableAnnotation.Oblivious)
596typeWithAnnotationsPredicate: (t, a, b) => t.NullableAnnotation != NullableAnnotation.Oblivious && !t.Type.IsErrorType() && !t.Type.IsValueType,
633var annotation = typeWithAnnotations.NullableAnnotation;
709if (result.NullableAnnotation != NullableAnnotation.Oblivious &&
712result = CreateNonLazyType(newTypeSymbol, NullableAnnotation.Oblivious, result.CustomModifiers);
732return CreateNonLazyType(typeSymbol, NullableAnnotation.NotAnnotated, CustomModifiers);
740if (NullableAnnotation != NullableAnnotation.Oblivious)
745return CreateNonLazyType(newTypeSymbol, NullableAnnotation.Oblivious, CustomModifiers);
813static NullableFlowState getFlowState(TypeSymbol type, NullableAnnotation annotation)
821return annotation switch { NullableAnnotation.Annotated => NullableFlowState.MaybeDefault, NullableAnnotation.NotAnnotated => NullableFlowState.MaybeNull, _ => NullableFlowState.NotNull };
825return annotation switch { NullableAnnotation.Annotated => NullableFlowState.MaybeDefault, _ => NullableFlowState.NotNull };
831return annotation switch { NullableAnnotation.Annotated => NullableFlowState.MaybeNull, _ => NullableFlowState.NotNull };
853internal abstract NullableAnnotation GetResolvedAnnotation(NullableAnnotation defaultAnnotation);
894internal override NullableAnnotation GetResolvedAnnotation(NullableAnnotation defaultAnnotation) => defaultAnnotation;
921return CreateNonLazyType(type.DefaultType, NullableAnnotation.Annotated, _customModifiers);
927return CreateNonLazyType(defaultType, defaultType.IsNullableType() ? type.NullableAnnotation : NullableAnnotation.NotAnnotated, _customModifiers);
978internal override NullableAnnotation GetResolvedAnnotation(NullableAnnotation defaultAnnotation)
980Debug.Assert(defaultAnnotation == NullableAnnotation.Ignored);
987return (NullableAnnotation)_resolved;
989NullableAnnotation getResolvedAnnotationCore()
994return NullableAnnotation.NotAnnotated;
1000return NullableAnnotation.Oblivious;
1008internal override bool IsResolved => _resolved != (int)NullableAnnotation.Ignored;
1024return CreateNonLazyType(type.DefaultType, NullableAnnotation.Annotated, _customModifiers);
1030return CreateNonLazyType(defaultType, defaultType.IsNullableType() ? type.NullableAnnotation : NullableAnnotation.NotAnnotated, _customModifiers);
1051_ = GetResolvedAnnotation(NullableAnnotation.Ignored);
1109internal override NullableAnnotation GetResolvedAnnotation(NullableAnnotation defaultAnnotation) => defaultAnnotation;