Skip to content

Commit

Permalink
Remove stale !s and TODO-NULLABLEs, plus those for indexer nullabilit…
Browse files Browse the repository at this point in the history
…y tracking
  • Loading branch information
stephentoub committed Nov 2, 2020
1 parent 9c98063 commit e234898
Show file tree
Hide file tree
Showing 25 changed files with 73 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ private static Attribute[] InternalParamGetCustomAttributes(ParameterInfo param,
count = 0;
for (int i = 0; i < objAttr.Length; i++)
{
if (objAttr[i] != null)
if (objAttr[i] is object attr)
{
attributes[count] = (Attribute)objAttr[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
attributes[count] = (Attribute)attr;
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal override int IndexOf(T[] array, T value, int startIndex, int count)
{
for (int i = startIndex; i < endIndex; i++)
{
if (array[i] != null && array[i]!.Equals(value)) return i; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (array[i] != null && array[i]!.Equals(value)) return i;
}
}
return -1;
Expand All @@ -136,7 +136,7 @@ internal override int LastIndexOf(T[] array, T value, int startIndex, int count)
{
for (int i = startIndex; i >= endIndex; i--)
{
if (array[i] != null && array[i]!.Equals(value)) return i; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (array[i] != null && array[i]!.Equals(value)) return i;
}
}
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ private static bool TrySetSlot(object?[] a, int index, object o)

// The slot may be already set because we have added and removed the same method before.
// Optimize this case, because it's cheaper than copying the array.
if (a[index] != null)
if (a[index] is object ai)
{
MulticastDelegate d = (MulticastDelegate)o;
MulticastDelegate dd = (MulticastDelegate)a[index]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
MulticastDelegate dd = (MulticastDelegate)ai;

if (dd._methodPtr == d._methodPtr &&
dd._target == d._target &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1622,14 +1622,14 @@ internal void AddLocalSymInfoToCurrentScope(
{
int i = GetCurrentActiveScopeIndex();
m_localSymInfos[i] ??= new LocalSymInfo();
m_localSymInfos[i]!.AddLocalSymInfo(strName, signature, slot, startOffset, endOffset); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
m_localSymInfos[i]!.AddLocalSymInfo(strName, signature, slot, startOffset, endOffset);
}

internal void AddUsingNamespaceToCurrentScope(string strNamespace)
{
int i = GetCurrentActiveScopeIndex();
m_localSymInfos[i] ??= new LocalSymInfo();
m_localSymInfos[i]!.AddUsingNamespace(strNamespace); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
m_localSymInfos[i]!.AddUsingNamespace(strNamespace);
}

internal void AddScopeInfo(ScopeAction sa, int iOffset)
Expand Down Expand Up @@ -1693,9 +1693,9 @@ internal void EmitScopeTree(ISymbolWriter symWriter)
{
symWriter.CloseScope(m_iOffsets[i]);
}
if (m_localSymInfos[i] != null)
if (m_localSymInfos[i] is LocalSymInfo lsi)
{
m_localSymInfos[i]!.EmitLocalSymInfo(symWriter); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
lsi.EmitLocalSymInfo(symWriter);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3900,9 +3900,9 @@ private void CreateInstanceCheckThis()
Type[] argsType = new Type[args.Length];
for (int i = 0; i < args.Length; i++)
{
if (args[i] != null)
if (args[i] is object arg)
{
argsType[i] = args[i]!.GetType(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
argsType[i] = arg.GetType();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public DelegateWrapper(Delegate d, bool wrapArgs)
{
for (int i = 0; i < _expectedParamsCount; i++)
{
if (_cachedTargetTypes[i] != null)
if (_cachedTargetTypes[i] is Type t)
{
args[i] = Enum.ToObject(_cachedTargetTypes[i]!, args[i]); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
args[i] = Enum.ToObject(t, args[i]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,15 +1089,16 @@ private static List<WaitHandle> GetHandles(BlockingCollection<T>[] collections,
List<CancellationToken> tokensList = new List<CancellationToken>(collections.Length + 1); // + 1 for the external token
tokensList.Add(externalCancellationToken);

//Read the appropriate WaitHandle based on the operation mode.
// Read the appropriate WaitHandle based on the operation mode.
if (isAddOperation)
{
for (int i = 0; i < collections.Length; i++)
{
if (collections[i]._freeNodes != null)
BlockingCollection<T> c = collections[i];
if (c._freeNodes != null)
{
handlesList.Add(collections[i]._freeNodes!.AvailableWaitHandle); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
tokensList.Add(collections[i]._producersCancellationTokenSource.Token);
handlesList.Add(c._freeNodes.AvailableWaitHandle);
tokensList.Add(c._producersCancellationTokenSource.Token);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ public override int GetHashCode()
{
return MemberType.GetHashCode() ^ _accessorsCreator.GetHashCode();
}
else

if (_accessors != null && _accessors[0] is MemberInfo accessor)
{
if (_accessors == null || _accessors[0] == null)
{
throw new Exception(SR.Diagnostic_InternalExceptionMessage);
}
return MemberType.GetHashCode() ^ _accessors[0]!.GetHashCode(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
return MemberType.GetHashCode() ^ accessor.GetHashCode();
}

throw new Exception(SR.Diagnostic_InternalExceptionMessage);
}

public override bool Equals(object? obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ public override bool Equals(object? obj)

for (int i = 0; i < Count; i++)
{
if (InnerList[i] != other.InnerList[i])
object? thisObj = InnerList[i];
object? otherObj = other.InnerList[i];
if (thisObj != otherObj)
{
if (InnerList[i] == null || !InnerList[i]!.Equals(other.InnerList[i])) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
if (thisObj is null || !thisObj.Equals(otherObj))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,11 @@ internal static void GetPrintDialogInfo(string printer, ref string port, ref str

NameValueCollection options = LoadPrinterOptions(cups_dests.options, cups_dests.num_options);

if (options["printer-state"] != null)
state = int.Parse(options["printer-state"]!); // TODO-NULLABLE dotnet/roslyn#34644
if (options["printer-state"] is string printerState)
state = int.Parse(printerState);

if (options["printer-comment"] != null)
comment = options["printer-state"]!; // TODO-NULLABLE dotnet/roslyn#34644
if (options["printer-comment"] is string printerComment)
comment = printerComment;

switch (state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ internal static void DumpHeaders(StringBuilder sb, params HttpHeaders?[] headers

for (int i = 0; i < headers.Length; i++)
{
if (headers[i] != null)
if (headers[i] is HttpHeaders hh)
{
foreach (var header in headers[i]!) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
foreach (KeyValuePair<string, IEnumerable<string>> header in hh)
{
foreach (var headerValue in header.Value)
foreach (string headerValue in header.Value)
{
sb.Append(" ");
sb.Append(header.Key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public virtual bool Contains(object? item)
else
{
for (int i = 0; i < _size; i++)
if ((_items[i] != null) && (_items[i]!.Equals(item))) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (_items[i] is object o && o.Equals(item))
return true;
return false;
}
Expand Down Expand Up @@ -916,7 +916,7 @@ public override int IndexOf(object? value, int startIndex, int count)
else
{
for (int i = startIndex; i < endIndex; i++)
if (_list[i] != null && _list[i]!.Equals(value)) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (_list[i] is object o && o.Equals(value))
return i;
return -1;
}
Expand Down Expand Up @@ -984,7 +984,7 @@ public override int LastIndexOf(object? value, int startIndex, int count)
else
{
for (int i = startIndex; i >= endIndex; i--)
if (_list[i] != null && _list[i]!.Equals(value)) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (_list[i] is object o && o.Equals(value))
return i;
return -1;
}
Expand Down Expand Up @@ -2311,7 +2311,7 @@ public override bool Contains(object? item)
else
{
for (int i = 0; i < _baseSize; i++)
if (_baseList[_baseIndex + i] != null && _baseList[_baseIndex + i]!.Equals(item)) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (_baseList[_baseIndex + i] is object o && o.Equals(item))
return true;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public sealed override MethodBase BindToMethod(
continue;

// Validate the parameters.
ParameterInfo[] par = candidates[i]!.GetParametersNoCopy(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
ParameterInfo[] par = candidates[i]!.GetParametersNoCopy();

#region Match method by parameter count
if (par.Length == 0)
{
#region No formal parameters
if (args.Length != 0)
{
if ((candidates[i]!.CallingConvention & CallingConventions.VarArgs) == 0) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if ((candidates[i]!.CallingConvention & CallingConventions.VarArgs) == 0)
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private static string Serialize(ReadOnlyCollection<string>? payloadName, ReadOnl
}
default:
{
if (payload[i] != null)
if (payload[i] is object o)
{
sb.Append(payload[i]!.ToString()); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
sb.Append(o.ToString());
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,26 @@ internal static bool TryParseExactMultiple(ReadOnlySpan<char> s, string?[]? form
//
for (int i = 0; i < formats.Length; i++)
{
if (formats[i] == null || formats[i]!.Length == 0) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
string? format = formats[i];
if (string.IsNullOrEmpty(format))
{
result.SetBadFormatSpecifierFailure();
return false;
}

// Create a new result each time to ensure the runs are independent. Carry through
// flags from the caller and return the result.
DateTimeResult innerResult = default; // The buffer to store the parsing result.
innerResult.Init(s);
innerResult.flags = result.flags;
if (TryParseExact(s, formats[i], dtfi, style, ref innerResult))
if (TryParseExact(s, format, dtfi, style, ref innerResult))
{
result.parsedDate = innerResult.parsedDate;
result.timeZoneOffset = innerResult.timeZoneOffset;
return true;
}
}

result.SetBadDateTimeFailure();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ private Type FindType(int typeIndex)
}
}
Debug.Assert(_typeTable[typeIndex] != null, "Should have found a type!");
return _typeTable[typeIndex]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
return _typeTable[typeIndex]!;
}

private string TypeNameFromTypeCode(ResourceTypeCode typeCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,15 +1340,15 @@ private unsafe StringBuilder AppendJoinCore<T>(char* separator, int separatorLen

if (values[0] != null)
{
Append(values[0]!.ToString()); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
Append(values[0]!.ToString());
}

for (int i = 1; i < values.Length; i++)
{
Append(separator, separatorLength);
if (values[i] != null)
{
Append(values[i]!.ToString()); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
Append(values[i]!.ToString());
}
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ private static int WaitMultiple(ReadOnlySpan<WaitHandle> waitHandles, bool waitA
{
for (int i = 0; i < waitHandles.Length; ++i)
{
if (safeWaitHandles[i] != null)
if (safeWaitHandles[i] is SafeWaitHandle swh)
{
safeWaitHandles[i]!.DangerousRelease(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
swh.DangerousRelease();
safeWaitHandles[i] = null;
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public virtual Type[] FindInterfaces(TypeFilter filter, object? filterCriteria)
cnt = 0;
for (int i = 0; i < c.Length; i++)
{
if (c[i] != null)
ret[cnt++] = c[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (c[i] is Type t)
ret[cnt++] = t!;
}
return ret;
}
Expand Down Expand Up @@ -272,47 +272,47 @@ public virtual MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bin
{
for (i = 0; i < m.Length; i++)
if (m[i] != null)
ret[cnt++] = m[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
ret[cnt++] = m[i]!;
}

// Copy the Constructors
if (c != null)
{
for (i = 0; i < c.Length; i++)
if (c[i] != null)
ret[cnt++] = c[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (c[i] is ConstructorInfo ci)
ret[cnt++] = ci;
}

// Copy the Fields
if (f != null)
{
for (i = 0; i < f.Length; i++)
if (f[i] != null)
ret[cnt++] = f[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (f[i] is FieldInfo fi)
ret[cnt++] = fi;
}

// Copy the Properties
if (p != null)
{
for (i = 0; i < p.Length; i++)
if (p[i] != null)
ret[cnt++] = p[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (p[i] is PropertyInfo pi)
ret[cnt++] = pi;
}

// Copy the Events
if (e != null)
{
for (i = 0; i < e.Length; i++)
if (e[i] != null)
ret[cnt++] = e[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (e[i] is EventInfo ei)
ret[cnt++] = ei;
}

// Copy the Types
if (t != null)
{
for (i = 0; i < t.Length; i++)
if (t[i] != null)
ret[cnt++] = t[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
if (t[i] is Type type)
ret[cnt++] = type;
}

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ internal void Reset()
public override string XmlLang { get { return IsXmlDataNode ? _xmlNodeReader.XmlLang : base.XmlLang; } }
public override string this[int i] { get { return IsXmlDataNode ? _xmlNodeReader[i] : GetAttribute(i); } }
public override string? this[string name] { get { return IsXmlDataNode ? _xmlNodeReader[name] : GetAttribute(name); } }
// TODO-NULLABLE - unnecessary namespaceURI! - https://github.com/dotnet/roslyn/issues/47221
public override string? this[string name, string? namespaceURI] { get { return IsXmlDataNode ? _xmlNodeReader[name, namespaceURI!] : GetAttribute(name, namespaceURI); } }
public override string? this[string name, string? namespaceURI] { get { return IsXmlDataNode ? _xmlNodeReader[name, namespaceURI] : GetAttribute(name, namespaceURI); } }

public override bool MoveToFirstAttribute()
{
Expand Down
Loading

0 comments on commit e234898

Please sign in to comment.