@@ -131,7 +131,7 @@ public static bool ContainsTypeParameters(this ITypeSymbol type, Context cx, ISy
131131 /// <param name="cx">The extraction context.</param>
132132 /// <param name="trapFile">The trap builder used to store the result.</param>
133133 /// <param name="subTermAction">The action to apply to syntactic sub terms of this type.</param>
134- public static void BuildTypeId ( this ITypeSymbol type , Context cx , TextWriter trapFile , bool prefix , Action < Context , TextWriter , ITypeSymbol > subTermAction )
134+ public static void BuildTypeId ( this ITypeSymbol type , Context cx , TextWriter trapFile , bool prefix , ISymbol SymbolBeingDefined , Action < Context , TextWriter , ITypeSymbol , ISymbol > subTermAction )
135135 {
136136 if ( type . SpecialType != SpecialType . None && ! ( type is INamedTypeSymbol n && n . IsGenericType ) )
137137 {
@@ -150,7 +150,7 @@ public static void BuildTypeId(this ITypeSymbol type, Context cx, TextWriter tra
150150 {
151151 case TypeKind . Array :
152152 var array = ( IArrayTypeSymbol ) type ;
153- subTermAction ( cx , trapFile , array . ElementType ) ;
153+ subTermAction ( cx , trapFile , array . ElementType , SymbolBeingDefined ) ;
154154 array . BuildArraySuffix ( trapFile ) ;
155155 return ;
156156 case TypeKind . Class :
@@ -160,15 +160,30 @@ public static void BuildTypeId(this ITypeSymbol type, Context cx, TextWriter tra
160160 case TypeKind . Delegate :
161161 case TypeKind . Error :
162162 var named = ( INamedTypeSymbol ) type ;
163- named . BuildNamedTypeId ( cx , trapFile , prefix , subTermAction ) ;
163+ named . BuildNamedTypeId ( cx , trapFile , prefix , SymbolBeingDefined , subTermAction ) ;
164164 return ;
165165 case TypeKind . Pointer :
166166 var ptr = ( IPointerTypeSymbol ) type ;
167- subTermAction ( cx , trapFile , ptr . PointedAtType ) ;
167+ subTermAction ( cx , trapFile , ptr . PointedAtType , SymbolBeingDefined ) ;
168168 trapFile . Write ( '*' ) ;
169169 return ;
170170 case TypeKind . TypeParameter :
171171 var tp = ( ITypeParameterSymbol ) type ;
172+ if ( ! SymbolEqualityComparer . Default . Equals ( tp . ContainingSymbol , SymbolBeingDefined ) )
173+ {
174+ switch ( tp . TypeParameterKind )
175+ {
176+ case TypeParameterKind . Method :
177+ var method = Method . Create ( cx , ( IMethodSymbol ) tp . ContainingSymbol ) ;
178+ trapFile . WriteSubId ( method ) ;
179+ trapFile . Write ( '_' ) ;
180+ break ;
181+ case TypeParameterKind . Type :
182+ subTermAction ( cx , trapFile , tp . ContainingType , SymbolBeingDefined ) ;
183+ trapFile . Write ( '_' ) ;
184+ break ;
185+ }
186+ }
172187 trapFile . Write ( tp . Name ) ;
173188 return ;
174189 case TypeKind . Dynamic :
@@ -211,7 +226,7 @@ private static void BuildAssembly(IAssemblySymbol asm, TextWriter trapFile, bool
211226 trapFile . Write ( "::" ) ;
212227 }
213228
214- static void BuildNamedTypeId ( this INamedTypeSymbol named , Context cx , TextWriter trapFile , bool prefixAssembly , Action < Context , TextWriter , ITypeSymbol > subTermAction )
229+ static void BuildNamedTypeId ( this INamedTypeSymbol named , Context cx , TextWriter trapFile , bool prefixAssembly , ISymbol symbolBeingDefined , Action < Context , TextWriter , ITypeSymbol , ISymbol > subTermAction )
215230 {
216231 if ( named . ContainingAssembly is null ) prefixAssembly = false ;
217232
@@ -223,7 +238,7 @@ static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter
223238 {
224239 trapFile . Write ( f . Name ) ;
225240 trapFile . Write ( ":" ) ;
226- subTermAction ( cx , tb0 , f . Type ) ;
241+ subTermAction ( cx , tb0 , f . Type , symbolBeingDefined ) ;
227242 }
228243 ) ;
229244 trapFile . Write ( ")" ) ;
@@ -232,7 +247,7 @@ static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter
232247
233248 if ( named . ContainingType != null )
234249 {
235- subTermAction ( cx , trapFile , named . ContainingType ) ;
250+ subTermAction ( cx , trapFile , named . ContainingType , symbolBeingDefined ) ;
236251 trapFile . Write ( '.' ) ;
237252 }
238253 else if ( named . ContainingNamespace != null )
@@ -254,14 +269,14 @@ static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter
254269 }
255270 else
256271 {
257- subTermAction ( cx , trapFile , named . ConstructedFrom ) ;
272+ subTermAction ( cx , trapFile , named . ConstructedFrom , symbolBeingDefined ) ;
258273 trapFile . Write ( '<' ) ;
259274 // Encode the nullability of the type arguments in the label.
260275 // Type arguments with different nullability can result in
261276 // a constructed type with different nullability of its members and methods,
262277 // so we need to create a distinct database entity for it.
263278 trapFile . BuildList ( "," , named . GetAnnotatedTypeArguments ( ) ,
264- ( ta , tb0 ) => subTermAction ( cx , tb0 , ta . Symbol )
279+ ( ta , tb0 ) => subTermAction ( cx , tb0 , ta . Symbol , symbolBeingDefined )
265280 ) ;
266281 trapFile . Write ( '>' ) ;
267282 }
@@ -273,16 +288,16 @@ static void BuildNamespace(this INamespaceSymbol ns, Context cx, TextWriter trap
273288 trapFile . Write ( '.' ) ;
274289 }
275290
276- static void BuildAnonymousName ( this ITypeSymbol type , Context cx , TextWriter trapFile , Action < Context , TextWriter , ITypeSymbol > subTermAction , bool includeParamName )
291+ static void BuildAnonymousName ( this ITypeSymbol type , Context cx , TextWriter trapFile , Action < Context , TextWriter , ITypeSymbol , ISymbol > subTermAction , bool includeParamName )
277292 {
278293 var buildParam = includeParamName
279294 ? ( prop , tb0 ) =>
280295 {
281296 tb0 . Write ( prop . Name ) ;
282297 tb0 . Write ( ' ' ) ;
283- subTermAction ( cx , tb0 , prop . Type ) ;
298+ subTermAction ( cx , tb0 , prop . Type , null ) ;
284299 }
285- : ( Action < IPropertySymbol , TextWriter > ) ( ( prop , tb0 ) => subTermAction ( cx , tb0 , prop . Type ) ) ;
300+ : ( Action < IPropertySymbol , TextWriter > ) ( ( prop , tb0 ) => subTermAction ( cx , tb0 , prop . Type , null ) ) ;
286301 int memberCount = type . GetMembers ( ) . OfType < IPropertySymbol > ( ) . Count ( ) ;
287302 int hackTypeNumber = memberCount == 1 ? 1 : 0 ;
288303 trapFile . Write ( "<>__AnonType" ) ;
@@ -354,7 +369,7 @@ public static void BuildNamedTypeDisplayName(this INamedTypeSymbol namedType, Co
354369
355370 if ( namedType . IsAnonymousType )
356371 {
357- namedType . BuildAnonymousName ( cx , trapFile , ( cx0 , tb0 , sub ) => sub . BuildDisplayName ( cx0 , tb0 ) , false ) ;
372+ namedType . BuildAnonymousName ( cx , trapFile , ( cx0 , tb0 , sub , _ ) => sub . BuildDisplayName ( cx0 , tb0 ) , false ) ;
358373 }
359374
360375 trapFile . Write ( namedType . Name ) ;
0 commit comments