private bool UsesIsNullable(TypeSymbolWithAnnotations type, ConsList <TypeParameterSymbol> inProgress)
        {
            if (type.IsNull)
            {
                return(false);
            }
            var typeSymbol = type.TypeSymbol;

            return((type.IsNullable != null && type.IsReferenceType && !type.IsErrorType()) ||
                   UsesIsNullable(type.TypeSymbol, inProgress));
        }
Beispiel #2
0
        internal void SetType(TypeSymbolWithAnnotations newType)
        {
            Debug.Assert(!(newType.TypeSymbol is null));
            TypeSymbol originalType = _type.DefaultType;

            // In the event that we race to set the type of a local, we should
            // always deduce the same type, or deduce that the type is an error.

            Debug.Assert((object)originalType == null ||
                         originalType.IsErrorType() && newType.IsErrorType() ||
                         TypeSymbol.Equals(originalType, newType.TypeSymbol, TypeCompareKind.ConsiderEverything2));

            if ((object)originalType == null)
            {
                _type.InterlockedInitialize(newType);
            }
        }
 private static bool IsNullableReference(TypeSymbolWithAnnotations type)
 => type.IsNull || !(type.IsValueType || type.IsErrorType());
Beispiel #4
0
 /// <summary>
 /// A `?` annotation on a type that isn't a value type causes:
 /// - an error before C# 8.0
 /// - a warning outside of a NonNullTypes context
 /// </summary>
 public static DiagnosticInfo ReportNullableReferenceTypesIfNeeded(CSharpCompilation compilation, INonNullTypesContext context, TypeSymbolWithAnnotations type)
 {
     return(!type.IsNull && (type.IsValueType || type.IsErrorType()) ? null : ReportNullableReferenceTypesIfNeeded(compilation, context));
 }
 /// <summary>
 /// A `?` annotation on a type that isn't a value type causes:
 /// - an error before C# 8.0
 /// - a warning outside of a NonNullTypes context
 /// </summary>
 public static DiagnosticInfo ReportNullableReferenceTypesIfNeeded(CSharpCompilation compilation, bool isNullableEnabled, TypeSymbolWithAnnotations type)
 {
     return(!type.IsNull && (type.IsValueType || type.IsErrorType()) ? null : ReportNullableReferenceTypesIfNeeded(compilation, isNullableEnabled));
 }