Browse Source

Fix NullReferenceException on overload invocation with null parameter

If more than 1 overload matching arguments number is found, JINT tries
to look for the best match comparing desired argument type and actual
argument type. GetType on null throws NullReferenceException.
h15ter 11 years ago
parent
commit
97304e3107
1 changed files with 12 additions and 1 deletions
  1. 12 1
      Jint/Runtime/TypeConverter.cs

+ 12 - 1
Jint/Runtime/TypeConverter.cs

@@ -366,7 +366,18 @@ namespace Jint.Runtime
                 var parameters = method.GetParameters();
                 for (var i = 0; i < arguments.Length; i++)
                 {
-                    if (objectArguments[i].GetType() != parameters[i].ParameterType)
+                    var arg = objectArguments[i];
+                    var paramType = parameters[i].ParameterType;
+                    
+                    if (arg == null)
+                    {
+                        if (paramType.IsValueType && Nullable.GetUnderlyingType(paramType) == null)
+                        {
+                            perfectMatch = false;
+                            break;
+                        }
+                    }
+                    else if (arg.GetType() != paramType)
                     {
                         perfectMatch = false;
                         break;