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 0099c86
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 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,6 +1482,11 @@ private boolean isFunctionTypeAssignable(BInvokableType source, BInvokableType t
return checkFunctionTypeEquality(source, target, unresolvedTypes, (s, t, ut) -> isAssignable(t, s, ut));
}

private boolean isTypeParamAssignable(BType sourceParam, BType targetParam) {
return isAssignable(sourceParam, targetParam) ||
(isAssignable(sourceParam, symTable.xmlType) && isAssignable(targetParam, sourceParam));
}

public boolean constituentTypesAssignable(BType varType, BType typeNodeType) {
if (varType.tag == TypeTags.XML) {
typeNodeType = getReferredType(typeNodeType);
Expand Down Expand Up @@ -2072,8 +2077,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 0099c86

Please sign in to comment.