summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-07-09 00:58:11 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-07-09 00:58:11 -0400
commit1fd52f8b63d2369de84b7ab8d54596d2cb597abf (patch)
tree06019ffd39fe2f9c2c16cac9b4118861f497ab2f /src/SMAPI
parentfbf8356452db76f902578072aab3d757497e4cd1 (diff)
downloadSMAPI-1fd52f8b63d2369de84b7ab8d54596d2cb597abf.tar.gz
SMAPI-1fd52f8b63d2369de84b7ab8d54596d2cb597abf.tar.bz2
SMAPI-1fd52f8b63d2369de84b7ab8d54596d2cb597abf.zip
detect broken constructor references
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs11
-rw-r--r--src/SMAPI/Framework/ModLoading/RewriteHelper.cs2
2 files changed, 8 insertions, 5 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
index f5e33313..b95dd79c 100644
--- a/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
+++ b/src/SMAPI/Framework/ModLoading/Finders/ReferenceToMissingMemberFinder.cs
@@ -67,12 +67,15 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders
MethodReference methodRef = RewriteHelper.AsMethodReference(instruction);
if (methodRef != null && this.ShouldValidate(methodRef.DeclaringType) && !this.IsUnsupported(methodRef))
{
- MethodDefinition target = methodRef.DeclaringType.Resolve()?.Methods.FirstOrDefault(p => p.Name == methodRef.Name);
+ MethodDefinition target = methodRef.Resolve();
if (target == null)
{
- this.NounPhrase = this.IsProperty(methodRef)
- ? $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name.Substring(4)} (no such property)"
- : $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name} (no such method)";
+ if (this.IsProperty(methodRef))
+ this.NounPhrase = $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name.Substring(4)} (no such property)";
+ else if (methodRef.Name == ".ctor")
+ this.NounPhrase = $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name} (no matching constructor)";
+ else
+ this.NounPhrase = $"reference to {methodRef.DeclaringType.FullName}.{methodRef.Name} (no such method)";
return InstructionHandleResult.NotCompatible;
}
}
diff --git a/src/SMAPI/Framework/ModLoading/RewriteHelper.cs b/src/SMAPI/Framework/ModLoading/RewriteHelper.cs
index 2f79809c..9ff43d45 100644
--- a/src/SMAPI/Framework/ModLoading/RewriteHelper.cs
+++ b/src/SMAPI/Framework/ModLoading/RewriteHelper.cs
@@ -32,7 +32,7 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <param name="instruction">The IL instruction.</param>
public static MethodReference AsMethodReference(Instruction instruction)
{
- return instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt
+ return instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt || instruction.OpCode == OpCodes.Newobj
? (MethodReference)instruction.Operand
: null;
}