Skip to content

Commit

Permalink
Fix bstring array tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Dec 16, 2024
1 parent 2b57fa4 commit 64f3005
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ public static boolean anyToJBoolean(Object sourceVal) {
*/
public static boolean checkIsType(Object sourceVal, Type targetType) {
Type sourceType = getType(sourceVal);
if (sourceType == targetType || (sourceType.getTag() == targetType.getTag() && sourceType.equals(targetType))) {
return true;
}
if (isSubType(sourceType, targetType)) {
return true;
}
Expand Down Expand Up @@ -604,7 +601,10 @@ private static boolean isSubTypeWithInherentType(Context cx, Object sourceValue,
.orElse(false);
}

private static synchronized boolean isSubType(Type source, Type target) {
private static boolean isSubType(Type source, Type target) {
if (source == target || (source.getTag() == target.getTag() && source.equals(target))) {
return true;
}
if (source instanceof CacheableTypeDescriptor sourceCacheableType &&
target instanceof CacheableTypeDescriptor targetCacheableType) {
return isSubTypeWithCache(sourceCacheableType, targetCacheableType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,22 +660,21 @@ public void setArrayRefTypeForcefully(ArrayType type, int size) {
}

public void addInt(long index, long value) {
Type sourceType = TypeChecker.getType(value);
if (intValues != null) {
if (elementType == PredefinedTypes.TYPE_INT) {
if (sourceType == this.elementType) {
prepareForAddWithoutTypeCheck(index, intValues.length);
} else {
// We need type checker for int subtypes
prepareForAdd(index, value, intValues.length);
}
intValues[(int) index] = value;
return;
}
if (!TypeChecker.isByteLiteral(value)) {
throw ErrorCreator.createError(getModulePrefixedReason(ARRAY_LANG_LIB,
INHERENT_TYPE_VIOLATION_ERROR_IDENTIFIER), ErrorHelper.getErrorDetails(
ErrorCodes.INCOMPATIBLE_TYPE, this.elementType, TypeChecker.getType(value)));
if (sourceType == this.elementType) {
prepareForAddWithoutTypeCheck(index, byteValues.length);
} else {
prepareForAdd(index, value, byteValues.length);
}
prepareForAddWithoutTypeCheck(index, byteValues.length);
byteValues[(int) index] = (byte) ((Long) value).intValue();
}

Expand All @@ -700,7 +699,12 @@ private void addString(long index, String value) {
}

private void addBString(long index, BString value) {
prepareForAddWithoutTypeCheck(index, bStringValues.length);
Type sourceType = TypeChecker.getType(value);
if (sourceType == this.elementType) {
prepareForAddWithoutTypeCheck(index, bStringValues.length);
} else {
prepareForAdd(index, value, bStringValues.length);
}
bStringValues[(int) index] = value;
}

Expand Down

0 comments on commit 64f3005

Please sign in to comment.