fix false broken-code detection when referencing a generic type (#453)

This commit is contained in:
Jesse Plamondon-Willard 2018-03-04 02:25:37 -05:00
parent 9a9622702a
commit d0b66b13bd
1 changed files with 8 additions and 0 deletions

View File

@ -48,6 +48,10 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction);
if (fieldRef != null)
{
// can't compare generic type parameters between definition and reference
if (fieldRef.FieldType.IsGenericInstance || fieldRef.FieldType.IsGenericParameter)
return InstructionHandleResult.None;
// get target field
FieldDefinition targetField = fieldRef.DeclaringType.Resolve()?.Fields.FirstOrDefault(p => p.Name == fieldRef.Name);
if (targetField == null)
@ -67,6 +71,10 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
MethodReference methodReference = RewriteHelper.AsMethodReference(instruction);
if (methodReference != null)
{
// can't compare generic type parameters between definition and reference
if (methodReference.ReturnType.IsGenericInstance || methodReference.ReturnType.IsGenericParameter)
return InstructionHandleResult.None;
// get potential targets
MethodDefinition[] candidateMethods = methodReference.DeclaringType.Resolve()?.Methods.Where(found => found.Name == methodReference.Name).ToArray();
if (candidateMethods == null || !candidateMethods.Any())