Skip to content

Commit c77fbd9

Browse files
committed
Resolve methods with numeric parameters
1 parent f005e48 commit c77fbd9

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

Jurassic/Compiler/Binders/BinderUtilities.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,48 @@ public static int ResolveOverloads(RuntimeMethodHandle[] methodHandles, ScriptEn
5656

5757
// Get the type of the output parameter.
5858
Type outputType = argument.Type;
59+
TypeCode typeCode = Type.GetTypeCode(outputType);
5960

60-
switch (Type.GetTypeCode(outputType))
61+
62+
switch (typeCode)
6163
{
6264
case TypeCode.Boolean:
6365
if ((input is bool) == false)
6466
demeritPoints[i] += disqualification;
6567
break;
6668

6769
case TypeCode.SByte:
68-
case TypeCode.Int16:
69-
case TypeCode.Int32:
70-
case TypeCode.Int64:
7170
case TypeCode.Byte:
7271
case TypeCode.UInt16:
7372
case TypeCode.UInt32:
7473
case TypeCode.UInt64:
74+
case TypeCode.Int16:
75+
case TypeCode.Int32:
76+
case TypeCode.Int64:
7577
case TypeCode.Single:
7678
case TypeCode.Decimal:
79+
case TypeCode.Double:
80+
Dictionary<TypeCode, int> offsetDict = new Dictionary<TypeCode, int>() { { TypeCode.SByte, 10 },
81+
{ TypeCode.Byte, 9 },
82+
{ TypeCode.UInt16, 8 },
83+
{ TypeCode.UInt32, 7 },
84+
{ TypeCode.UInt64, 6 },
85+
{ TypeCode.Int16, 5 },
86+
{ TypeCode.Int32, 4 },
87+
{ TypeCode.Int64, 3 },
88+
{ TypeCode.Single, 2 },
89+
{ TypeCode.Decimal, 1 },
90+
{ TypeCode.Double, 0 }
91+
};
92+
93+
// To fix ambiguous methods error when there are method with numeric parameters
94+
// double has maximal priority
7795
if (TypeUtilities.IsNumeric(input) == true)
78-
demeritPoints[i] ++;
96+
demeritPoints[i] += offsetDict[typeCode];
7997
else
8098
demeritPoints[i] += disqualification;
8199
break;
82100

83-
case TypeCode.Double:
84-
if (TypeUtilities.IsNumeric(input) == false)
85-
demeritPoints[i] += disqualification;
86-
break;
87-
88101
case TypeCode.Char:
89102
if (TypeUtilities.IsString(input) == true)
90103
demeritPoints[i]++;
@@ -125,6 +138,11 @@ public static int ResolveOverloads(RuntimeMethodHandle[] methodHandles, ScriptEn
125138
case TypeCode.DBNull:
126139
throw new NotSupportedException(string.Format("{0} is not a supported parameter type.", outputType));
127140
}
141+
// To fix ambiguous methods error when there are method with smilar parameters, for example int32[] and int32
142+
if (argument.IsParamArrayArgument)
143+
{
144+
demeritPoints[i] += 100;
145+
}
128146
}
129147

130148
}

0 commit comments

Comments
 (0)