Skip to content

Commit

Permalink
Update NullabilityInfoContext.cs.pp with bug fix from MS repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 authored Jan 18, 2022
1 parent c2a216d commit 564e837
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/NullabilityInfo/NullabilityInfoContext.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,13 @@
return NotAnnotatedStatus.None;
}

private NullabilityInfo GetNullabilityInfo(MemberInfo memberInfo, Type type, IList<CustomAttributeData> customAttributes) =>
GetNullabilityInfo(memberInfo, type, customAttributes, 0);
private NullabilityInfo GetNullabilityInfo(MemberInfo memberInfo, Type type, IList<CustomAttributeData> customAttributes)
{
int index = 0;
return GetNullabilityInfo(memberInfo, type, customAttributes, ref index);
}

private NullabilityInfo GetNullabilityInfo(MemberInfo memberInfo, Type type, IList<CustomAttributeData> customAttributes, int index)
private NullabilityInfo GetNullabilityInfo(MemberInfo memberInfo, Type type, IList<CustomAttributeData> customAttributes, ref int index)
{
NullabilityState state = NullabilityState.Unknown;
NullabilityInfo? elementState = null;
Expand All @@ -365,17 +368,22 @@
underlyingType = type;
state = NullabilityState.NotNull;
}

if (underlyingType.IsGenericType)
{
index++;
}
}
else
{
if (!ParseNullableState(customAttributes, index, ref state))
if (!ParseNullableState(customAttributes, index++, ref state))
{
state = GetNullableContext(memberInfo);
}

if (type.IsArray)
{
elementState = GetNullabilityInfo(memberInfo, type.GetElementType()!, customAttributes, index + 1);
elementState = GetNullabilityInfo(memberInfo, type.GetElementType()!, customAttributes, ref index);
}
}

Expand All @@ -384,16 +392,9 @@
Type[] genericArguments = underlyingType.GetGenericArguments();
genericArgumentsState = new NullabilityInfo[genericArguments.Length];

for (int i = 0, offset = 0; i < genericArguments.Length; i++)
for (int i = 0; i < genericArguments.Length; i++)
{
Type t = Nullable.GetUnderlyingType(genericArguments[i]) ?? genericArguments[i];

if (!t.IsValueType || t.IsGenericType)
{
offset++;
}

genericArgumentsState[i] = GetNullabilityInfo(memberInfo, genericArguments[i], customAttributes, index + offset);
genericArgumentsState[i] = GetNullabilityInfo(memberInfo, genericArguments[i], customAttributes, ref index);
}
}

Expand Down Expand Up @@ -501,7 +502,8 @@
{
if (genericArguments[i].IsGenericParameter)
{
NullabilityInfo n = GetNullabilityInfo(metaMember, genericArguments[i], genericArguments[i].GetCustomAttributesData(), i + 1);
int index = i + 1;
NullabilityInfo n = GetNullabilityInfo(metaMember, genericArguments[i], genericArguments[i].GetCustomAttributesData(), ref index);
nullability.GenericTypeArguments[i].ReadState = n.ReadState;
nullability.GenericTypeArguments[i].WriteState = n.WriteState;
}
Expand All @@ -524,7 +526,8 @@
&& metaType.GetElementType()!.IsGenericParameter)
{
Type elementType = metaType.GetElementType()!;
NullabilityInfo n = GetNullabilityInfo(metaMember, elementType, elementType.GetCustomAttributesData(), 0);
int index = 0;
NullabilityInfo n = GetNullabilityInfo(metaMember, elementType, elementType.GetCustomAttributesData(), ref index);
elementState.ReadState = n.ReadState;
elementState.WriteState = n.WriteState;
}
Expand Down

0 comments on commit 564e837

Please sign in to comment.