Skip to content

Commit

Permalink
Update the use of isAssignable
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed May 17, 2024
1 parent 4c30cda commit 1f2bda9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4473,7 +4473,7 @@ private void handleForeachDefinitionVariables(VariableDefinitionNode variableDef
// If the type node is available, we get the type from it.
BType typeNodeType = symResolver.resolveTypeNode(variableNode.typeNode, blockEnv);
// Checking whether the RHS type is assignable to LHS type.
if (types.constituentTypesAssignable(varType, typeNodeType)) {
if (types.isAssignable(varType, typeNodeType)) {
if (onFail && varType == symTable.neverType) {
varType = typeNodeType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ private boolean isFunctionTypeAssignable(BInvokableType source, BInvokableType t
boolean isTypeParam = TypeParamAnalyzer.isTypeParam(targetParam);

if (isTypeParam) {
if (!constituentTypesAssignable(sourceParam, targetParam)) {
if (!isTypeParamAssignable(sourceParam, targetParam)) {
return false;
}
} else {
Expand All @@ -1482,15 +1482,9 @@ private boolean isFunctionTypeAssignable(BInvokableType source, BInvokableType t
return checkFunctionTypeEquality(source, target, unresolvedTypes, (s, t, ut) -> isAssignable(t, s, ut));
}

public boolean constituentTypesAssignable(BType varType, BType typeNodeType) {
if (varType.tag == TypeTags.XML) {
typeNodeType = getReferredType(typeNodeType);
if (typeNodeType.tag == TypeTags.UNION) {
return isAssignable(symTable.xmlItemType, typeNodeType);
}
return typeNodeType.tag == TypeTags.XML;
}
return isAssignable(varType, typeNodeType);
private boolean isTypeParamAssignable(BType sourceParam, BType targetParam) {
return isAssignable(sourceParam, targetParam) ||
(isAssignable(sourceParam, symTable.xmlType) && isAssignable(targetParam, sourceParam));
}

public boolean isInherentlyImmutableType(BType type) {
Expand Down Expand Up @@ -2072,8 +2066,7 @@ private BType getTypedBindingPatternTypeForXmlCollection(BType collectionType) {
Set<BType> collectionTypes = getEffectiveMemberTypes((BUnionType) constraint);
Set<BType> builtinXMLConstraintTypes = getEffectiveMemberTypes
((BUnionType) ((BXMLType) symTable.xmlType).constraint);
return collectionTypes.size() == 4 && builtinXMLConstraintTypes.equals(collectionTypes) ?
collectionType : BUnionType.create(null, (LinkedHashSet<BType>) collectionTypes);
return BUnionType.create(null, (LinkedHashSet<BType>) collectionTypes);
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public void testNegativeScenarios() {
validateError(negativeResult, index++,
"incompatible types: expected '(Type1 & readonly)', found '([int,int]|string|[int,int])'", 258, 51);
validateError(negativeResult, index++,
"incompatible types: expected '(xml & readonly)', found " +
"'xml'", 263, 41);
"incompatible types: expected '(xml & readonly)', found '" +
"(xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text)'", 263, 41);
validateError(negativeResult, index++,
"incompatible types: expected '(int[2] & readonly)', found 'int[2]'", 279, 69);
validateError(negativeResult, index++,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void setup() {
public void testNegativeQueryExprForXML() {
int index = 0;
validateError(negativeResult, index++, "incompatible types: expected " +
"'xml<((xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text) & readonly)> & readonly'," +
" found 'xml'", 21, 16);
"'xml<((xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text) & readonly)> & readonly'," +
" found '(xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text)'", 21, 16);
validateError(negativeResult, index++, "incompatible types: expected 'xml:Element & readonly', " +
"found 'xml:Element'", 25, 16);
validateError(negativeResult, index++,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void testNegative() {

int index = 0;
BAssertUtil.validateError(negative, index++,
"invalid list binding pattern: attempted to infer a list type, but found 'xml'",
13, 13);
"invalid list binding pattern: attempted to infer a list type, but found '" +
"(xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text)'", 13, 13);
BAssertUtil.validateError(negative, index++, "incompatible types: " +
"expected 'function (ballerina/lang.xml:0.0.0:ItemType) returns ()', " +
"found 'function ([int,xml,string]) returns ()'", 18, 19);
Expand Down

0 comments on commit 1f2bda9

Please sign in to comment.