@@ -257,6 +257,26 @@ private void FillTypeSpecsFromMemberReferences()
257
257
}
258
258
}
259
259
}
260
+
261
+ // make sure we pick up *all* GenericInstanceType that we know
262
+ // about via MethodSpecificationTable as well as TypeReferencesTable
263
+ IEnumerable < TypeReference > allGenericInstances =
264
+ _context . MethodSpecificationTable . Items
265
+ . OfType < GenericInstanceMethod > ( )
266
+ . Select ( ms => ms . DeclaringType as GenericInstanceType )
267
+ . Concat ( _context . TypeReferencesTable . Items . OfType < GenericInstanceType > ( ) )
268
+ . Where ( git => git != null )
269
+ . Distinct ( new TypeReferenceEqualityComparer ( _context ) ) ;
270
+
271
+ foreach ( TypeReference typeRefItem in allGenericInstances )
272
+ {
273
+ if ( ! _idByTypeSpecifications . ContainsKey ( typeRefItem ) )
274
+ {
275
+ ushort sigId = _context . SignaturesTable . GetOrCreateSignatureId ( typeRefItem ) ;
276
+ _idByTypeSpecifications . Add ( typeRefItem , sigId ) ;
277
+ ExpandNestedTypeSpecs ( typeRefItem ) ;
278
+ }
279
+ }
260
280
}
261
281
262
282
private void FillTypeSpecsFromTypes ( )
@@ -271,10 +291,39 @@ private void FillTypeSpecsFromTypes()
271
291
{
272
292
AddIfNew ( gp , _context . SignaturesTable . GetOrCreateSignatureId ( gp ) ) ;
273
293
}
294
+ else if ( instr . Operand is MethodReference mr )
295
+ {
296
+ // register return‐type...
297
+ ExpandNestedTypeSpecs ( mr . ReturnType ) ;
298
+
299
+ // ... and parameters
300
+ foreach ( ParameterDefinition p in mr . Parameters )
301
+ {
302
+ ExpandNestedTypeSpecs ( p . ParameterType ) ;
303
+ }
304
+ }
305
+
306
+ // catch field‐refs too
307
+ else if ( instr . Operand is FieldReference fieldRef )
308
+ {
309
+ ExpandNestedTypeSpecs ( fieldRef . DeclaringType ) ;
310
+ ExpandNestedTypeSpecs ( fieldRef . FieldType ) ;
311
+ }
312
+ else if ( instr . Operand is GenericInstanceMethod genericInstanceMethod )
313
+ {
314
+ GenericInstanceType genericInstanceType = genericInstanceMethod . DeclaringType as GenericInstanceType ;
315
+ if ( genericInstanceType != null && ! _idByTypeSpecifications . ContainsKey ( genericInstanceType ) )
316
+ {
317
+ ushort sigId = _context . SignaturesTable . GetOrCreateSignatureId ( genericInstanceType ) ;
318
+ _idByTypeSpecifications . Add ( genericInstanceType , sigId ) ;
319
+
320
+ // also pull in its element‐type and args
321
+ ExpandNestedTypeSpecs ( genericInstanceType ) ;
322
+ }
323
+ }
274
324
else if ( instr . Operand is TypeReference tr )
275
325
{
276
- // refuse multi-dimensional arrays
277
- // we only support jagged arrays
326
+ // refuse multi-dimensional arrays (we only support jagged arrays)
278
327
if ( tr . IsArray )
279
328
{
280
329
var at = ( ArrayType ) tr ;
@@ -286,12 +335,15 @@ private void FillTypeSpecsFromTypes()
286
335
}
287
336
}
288
337
289
- // register the type reference itself...
290
- ushort sigId = _context . SignaturesTable . GetOrCreateSignatureId ( tr ) ;
291
- AddIfNew ( tr , sigId ) ;
338
+ // register the type reference itself, if it is a TypeSpec
339
+ if ( tr is TypeSpecification )
340
+ {
341
+ ushort sigId = _context . SignaturesTable . GetOrCreateSignatureId ( tr ) ;
342
+ AddIfNew ( tr , sigId ) ;
292
343
293
- // ... then walk *into* any nested TypeSpecifications it might contain
294
- ExpandNestedTypeSpecs ( tr ) ;
344
+ // also walk into any nested TypeSpecifications it might contain
345
+ ExpandNestedTypeSpecs ( tr ) ;
346
+ }
295
347
}
296
348
}
297
349
}
@@ -316,7 +368,10 @@ private void ExpandNestedTypeSpecs(TypeReference t)
316
368
case GenericInstanceType git :
317
369
inner = git . ElementType ;
318
370
foreach ( var arg in git . GenericArguments )
371
+ {
319
372
ExpandNestedTypeSpecs ( arg ) ;
373
+ }
374
+
320
375
break ;
321
376
322
377
case ArrayType at :
@@ -340,7 +395,7 @@ private void ExpandNestedTypeSpecs(TypeReference t)
340
395
break ;
341
396
}
342
397
343
- if ( inner != null )
398
+ if ( inner is TypeSpecification )
344
399
{
345
400
ushort innerId = _context . SignaturesTable . GetOrCreateSignatureId ( inner ) ;
346
401
AddIfNew ( inner , innerId ) ;
0 commit comments