benaadams / Ben.Demystifier

High performance understanding for stack traces (Make error logs more productive)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArgumentOutOfRange when processing a nested type of a generic type

KirillOsenkov opened this issue · comments

  String.Substring Line 1282
  TypeNameHelper.GetTypeNameForGenericType Line 65
  ValueTupleResolvedParameter.AppendTypeName Line 23
  ResolvedParameter.Append Line 34
  ResolvedMethod.Append Line 93
  EnhancedStackTrace.Append Line 103
  EnhancedStackTrace.ToString Line 84

The exception is here:

return type.Name.Substring(0, genericPartIndex);

The type in question is:
Roslyn.Utilities.MultiDictionary2+ValueSet[Microsoft.CodeAnalysis.Document,System.ValueTuple2[Microsoft.CodeAnalysis.ISymbol,Microsoft.CodeAnalysis.FindSymbols.Finders.IReferenceFinder]]

http://sourceroslyn.io/#Microsoft.CodeAnalysis/InternalUtilities/MultiDictionary.cs,b9e522a001545166

Even though the type is a generic type, the name is just ValueSet and doesn't contains the backtick.

Here's a PR that adds a unit-test:
#110

It is significant that the method parameter type is a nested type of a generic type where the generic type parameter is a value tuple with named parameters.

Basically the logic for value tuples needs to be aware of nested types of generic types that themselves don't have a backtick in the name:

sb.Append(TypeNameHelper.GetTypeNameForGenericType(ResolvedType));
sb.Append("<");
AppendValueTupleParameterName(sb, ResolvedType.GetGenericArguments()[0]);
sb.Append(">");

Released a new version that doesn't have this issue; though not sure it makes it a sensible type name, looking into that