@@ -131,7 +131,7 @@ public static bool ContainsTypeParameters(this ITypeSymbol type, Context cx, ISy
131
131
/// <param name="cx">The extraction context.</param>
132
132
/// <param name="trapFile">The trap builder used to store the result.</param>
133
133
/// <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 )
135
135
{
136
136
if ( type . SpecialType != SpecialType . None && ! ( type is INamedTypeSymbol n && n . IsGenericType ) )
137
137
{
@@ -150,7 +150,7 @@ public static void BuildTypeId(this ITypeSymbol type, Context cx, TextWriter tra
150
150
{
151
151
case TypeKind . Array :
152
152
var array = ( IArrayTypeSymbol ) type ;
153
- subTermAction ( cx , trapFile , array . ElementType ) ;
153
+ subTermAction ( cx , trapFile , array . ElementType , SymbolBeingDefined ) ;
154
154
array . BuildArraySuffix ( trapFile ) ;
155
155
return ;
156
156
case TypeKind . Class :
@@ -160,15 +160,30 @@ public static void BuildTypeId(this ITypeSymbol type, Context cx, TextWriter tra
160
160
case TypeKind . Delegate :
161
161
case TypeKind . Error :
162
162
var named = ( INamedTypeSymbol ) type ;
163
- named . BuildNamedTypeId ( cx , trapFile , prefix , subTermAction ) ;
163
+ named . BuildNamedTypeId ( cx , trapFile , prefix , SymbolBeingDefined , subTermAction ) ;
164
164
return ;
165
165
case TypeKind . Pointer :
166
166
var ptr = ( IPointerTypeSymbol ) type ;
167
- subTermAction ( cx , trapFile , ptr . PointedAtType ) ;
167
+ subTermAction ( cx , trapFile , ptr . PointedAtType , SymbolBeingDefined ) ;
168
168
trapFile . Write ( '*' ) ;
169
169
return ;
170
170
case TypeKind . TypeParameter :
171
171
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
+ }
172
187
trapFile . Write ( tp . Name ) ;
173
188
return ;
174
189
case TypeKind . Dynamic :
@@ -211,7 +226,7 @@ private static void BuildAssembly(IAssemblySymbol asm, TextWriter trapFile, bool
211
226
trapFile . Write ( "::" ) ;
212
227
}
213
228
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 )
215
230
{
216
231
if ( named . ContainingAssembly is null ) prefixAssembly = false ;
217
232
@@ -223,7 +238,7 @@ static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter
223
238
{
224
239
trapFile . Write ( f . Name ) ;
225
240
trapFile . Write ( ":" ) ;
226
- subTermAction ( cx , tb0 , f . Type ) ;
241
+ subTermAction ( cx , tb0 , f . Type , symbolBeingDefined ) ;
227
242
}
228
243
) ;
229
244
trapFile . Write ( ")" ) ;
@@ -232,7 +247,7 @@ static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter
232
247
233
248
if ( named . ContainingType != null )
234
249
{
235
- subTermAction ( cx , trapFile , named . ContainingType ) ;
250
+ subTermAction ( cx , trapFile , named . ContainingType , symbolBeingDefined ) ;
236
251
trapFile . Write ( '.' ) ;
237
252
}
238
253
else if ( named . ContainingNamespace != null )
@@ -254,14 +269,14 @@ static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter
254
269
}
255
270
else
256
271
{
257
- subTermAction ( cx , trapFile , named . ConstructedFrom ) ;
272
+ subTermAction ( cx , trapFile , named . ConstructedFrom , symbolBeingDefined ) ;
258
273
trapFile . Write ( '<' ) ;
259
274
// Encode the nullability of the type arguments in the label.
260
275
// Type arguments with different nullability can result in
261
276
// a constructed type with different nullability of its members and methods,
262
277
// so we need to create a distinct database entity for it.
263
278
trapFile . BuildList ( "," , named . GetAnnotatedTypeArguments ( ) ,
264
- ( ta , tb0 ) => subTermAction ( cx , tb0 , ta . Symbol )
279
+ ( ta , tb0 ) => subTermAction ( cx , tb0 , ta . Symbol , symbolBeingDefined )
265
280
) ;
266
281
trapFile . Write ( '>' ) ;
267
282
}
@@ -273,16 +288,16 @@ static void BuildNamespace(this INamespaceSymbol ns, Context cx, TextWriter trap
273
288
trapFile . Write ( '.' ) ;
274
289
}
275
290
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 )
277
292
{
278
293
var buildParam = includeParamName
279
294
? ( prop , tb0 ) =>
280
295
{
281
296
tb0 . Write ( prop . Name ) ;
282
297
tb0 . Write ( ' ' ) ;
283
- subTermAction ( cx , tb0 , prop . Type ) ;
298
+ subTermAction ( cx , tb0 , prop . Type , null ) ;
284
299
}
285
- : ( Action < IPropertySymbol , TextWriter > ) ( ( prop , tb0 ) => subTermAction ( cx , tb0 , prop . Type ) ) ;
300
+ : ( Action < IPropertySymbol , TextWriter > ) ( ( prop , tb0 ) => subTermAction ( cx , tb0 , prop . Type , null ) ) ;
286
301
int memberCount = type . GetMembers ( ) . OfType < IPropertySymbol > ( ) . Count ( ) ;
287
302
int hackTypeNumber = memberCount == 1 ? 1 : 0 ;
288
303
trapFile . Write ( "<>__AnonType" ) ;
@@ -354,7 +369,7 @@ public static void BuildNamedTypeDisplayName(this INamedTypeSymbol namedType, Co
354
369
355
370
if ( namedType . IsAnonymousType )
356
371
{
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 ) ;
358
373
}
359
374
360
375
trapFile . Write ( namedType . Name ) ;
0 commit comments