use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol in project ballerina by ballerina-lang.
the class Desugar method addConversionExprIfRequired.
private BLangExpression addConversionExprIfRequired(BLangSimpleVarRef matchExprVarRef, BLangMatchStmtPatternClause patternClause) {
BType lhsType = patternClause.variable.type;
BType rhsType = matchExprVarRef.type;
if (types.isSameType(rhsType, lhsType)) {
return matchExprVarRef;
}
types.setImplicitCastExpr(matchExprVarRef, rhsType, lhsType);
if (matchExprVarRef.impConversionExpr != null) {
return matchExprVarRef;
}
BConversionOperatorSymbol conversionSymbol;
if (types.isValueType(lhsType) && !(rhsType.tag == TypeTags.JSON)) {
conversionSymbol = Symbols.createUnboxValueTypeOpSymbol(symTable.anyType, lhsType);
} else if (lhsType.tag == TypeTags.UNION || rhsType.tag == TypeTags.UNION) {
conversionSymbol = Symbols.createConversionOperatorSymbol(rhsType, lhsType, symTable.errStructType, false, true, InstructionCodes.NOP, null, null);
} else {
conversionSymbol = (BConversionOperatorSymbol) symResolver.resolveConversionOperator(rhsType, lhsType);
}
// Create a type cast expression
BLangTypeConversionExpr conversionExpr = (BLangTypeConversionExpr) TreeBuilder.createTypeConversionNode();
conversionExpr.expr = matchExprVarRef;
conversionExpr.targetType = lhsType;
conversionExpr.conversionSymbol = conversionSymbol;
conversionExpr.type = lhsType;
return conversionExpr;
}
Aggregations