Skip to content

Commit

Permalink
Resolve methods with numeric parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
objmalloc committed Apr 8, 2019
1 parent f005e48 commit c77fbd9
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions Jurassic/Compiler/Binders/BinderUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,48 @@ public static int ResolveOverloads(RuntimeMethodHandle[] methodHandles, ScriptEn

// Get the type of the output parameter.
Type outputType = argument.Type;
TypeCode typeCode = Type.GetTypeCode(outputType);

switch (Type.GetTypeCode(outputType))

switch (typeCode)
{
case TypeCode.Boolean:
if ((input is bool) == false)
demeritPoints[i] += disqualification;
break;

case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Byte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Single:
case TypeCode.Decimal:
case TypeCode.Double:
Dictionary<TypeCode, int> offsetDict = new Dictionary<TypeCode, int>() { { TypeCode.SByte, 10 },
{ TypeCode.Byte, 9 },
{ TypeCode.UInt16, 8 },
{ TypeCode.UInt32, 7 },
{ TypeCode.UInt64, 6 },
{ TypeCode.Int16, 5 },
{ TypeCode.Int32, 4 },
{ TypeCode.Int64, 3 },
{ TypeCode.Single, 2 },
{ TypeCode.Decimal, 1 },
{ TypeCode.Double, 0 }
};

// To fix ambiguous methods error when there are method with numeric parameters
// double has maximal priority
if (TypeUtilities.IsNumeric(input) == true)
demeritPoints[i] ++;
demeritPoints[i] += offsetDict[typeCode];
else
demeritPoints[i] += disqualification;
break;

case TypeCode.Double:
if (TypeUtilities.IsNumeric(input) == false)
demeritPoints[i] += disqualification;
break;

case TypeCode.Char:
if (TypeUtilities.IsString(input) == true)
demeritPoints[i]++;
Expand Down Expand Up @@ -125,6 +138,11 @@ public static int ResolveOverloads(RuntimeMethodHandle[] methodHandles, ScriptEn
case TypeCode.DBNull:
throw new NotSupportedException(string.Format("{0} is not a supported parameter type.", outputType));
}
// To fix ambiguous methods error when there are method with smilar parameters, for example int32[] and int32
if (argument.IsParamArrayArgument)
{
demeritPoints[i] += 100;
}
}

}
Expand Down

0 comments on commit c77fbd9

Please sign in to comment.