Skip to content

Commit

Permalink
Optimize convertible type for int subtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Aug 14, 2024
1 parent 5242407 commit ddf2a88
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,19 @@ public static boolean checkIsLikeType(Object sourceValue, Type targetType, boole
assert readonlyShape.isPresent();
SemType shape = readonlyShape.get();
SemType targetSemType = targetType;
if (allowNumericConversion) {
if (Core.isSubType(context(), shape, NUMERIC_TYPE) && allowNumericConversion) {
targetSemType = appendNumericConversionTypes(targetSemType);
}
return Core.isSubType(cx, shape, targetSemType);
}

private static SemType appendNumericConversionTypes(SemType semType) {
SemType result = semType;
result = Core.union(result, Core.intToFloat(semType));
result = Core.union(result, Core.intToDecimal(semType));
// We can represent any int value as a float or a decimal. This is to avoid the overhead of creating
// enumerable semtypes for them
if (Core.containsBasicType(semType, Builder.intType())) {
result = Core.union(Core.union(Builder.decimalType(), Builder.floatType()), result);
}
result = Core.union(result, Core.floatToInt(semType));
result = Core.union(result, Core.floatToDecimal(semType));
result = Core.union(result, Core.decimalToInt(semType));
Expand Down

0 comments on commit ddf2a88

Please sign in to comment.