use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangTypeofExpr accessExpr) {
BType actualType = symTable.typeDesc;
accessExpr.resolvedType = symResolver.resolveTypeNode(accessExpr.typeNode, env);
resultTypes = types.checkTypes(accessExpr, Lists.of(actualType), expTypes);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class TypeChecker method checkInvocationArgs.
private List<BType> checkInvocationArgs(BLangInvocation iExpr, List<BType> paramTypes, int requiredParamsCount, BLangExpression vararg) {
List<BType> actualTypes = getListWithErrorTypes(expTypes.size());
BInvokableSymbol invocableSymbol = (BInvokableSymbol) iExpr.symbol;
// Check whether the expected param count and the actual args counts are matching.
if (requiredParamsCount > iExpr.requiredArgs.size()) {
dlog.error(iExpr.pos, DiagnosticCode.NOT_ENOUGH_ARGS_FUNC_CALL, iExpr.name.value);
return actualTypes;
} else if (invocableSymbol.restParam == null && (vararg != null || !iExpr.restArgs.isEmpty())) {
dlog.error(iExpr.pos, DiagnosticCode.TOO_MANY_ARGS_FUNC_CALL, iExpr.name.value);
return actualTypes;
}
// formal parameters of the outer function.
if (iExpr.argExprs.size() == 1 && iExpr.argExprs.get(0).getKind() == NodeKind.INVOCATION) {
checkExpr(iExpr.requiredArgs.get(0), this.env, ((BInvokableType) invocableSymbol.type).paramTypes);
} else {
checkRequiredArgs(iExpr.requiredArgs, paramTypes);
}
checkNamedArgs(iExpr.namedArgs, invocableSymbol.defaultableParams);
checkRestArgs(iExpr.restArgs, vararg, invocableSymbol.restParam);
if (iExpr.async) {
return Arrays.asList(this.generateFutureType(invocableSymbol));
} else {
return invocableSymbol.type.getReturnTypes();
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class TypeChecker method setExprType.
private void setExprType(BLangExpression expr, List<BType> expTypes) {
int expected = expTypes.size();
if (expr instanceof MultiReturnExpr) {
MultiReturnExpr multiReturnExpr = (MultiReturnExpr) expr;
multiReturnExpr.setTypes(resultTypes);
} else {
if (expected > 1) {
dlog.error(expr.pos, DiagnosticCode.ASSIGNMENT_COUNT_MISMATCH, expected, 1);
resultTypes = getListWithErrorTypes(expected);
}
}
if (resultTypes.size() > 0) {
expr.type = resultTypes.get(0);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangTernaryExpr ternaryExpr) {
BType expType = checkExpr(ternaryExpr.expr, env, Lists.of(this.symTable.booleanType)).get(0);
BType thenType = checkExpr(ternaryExpr.thenExpr, env, expTypes).get(0);
BType elseType = checkExpr(ternaryExpr.elseExpr, env, expTypes).get(0);
if (expType == symTable.errType || thenType == symTable.errType || elseType == symTable.errType) {
resultTypes = Lists.of(symTable.errType);
} else if (expTypes.get(0) == symTable.noType) {
if (thenType == elseType) {
resultTypes = Lists.of(thenType);
} else {
dlog.error(ternaryExpr.pos, DiagnosticCode.INCOMPATIBLE_TYPES, thenType, elseType);
resultTypes = Lists.of(symTable.errType);
}
} else {
resultTypes = expTypes;
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class TypeChecker method visit.
public void visit(BLangXMLAttributeAccess xmlAttributeAccessExpr) {
BType actualType = symTable.errType;
// First analyze the variable reference expression.
checkExpr(xmlAttributeAccessExpr.expr, env, Lists.of(symTable.xmlType));
// Then analyze the index expression.
BLangExpression indexExpr = xmlAttributeAccessExpr.indexExpr;
if (indexExpr == null) {
if (xmlAttributeAccessExpr.lhsVar) {
dlog.error(xmlAttributeAccessExpr.pos, DiagnosticCode.XML_ATTRIBUTE_MAP_UPDATE_NOT_ALLOWED);
} else {
actualType = symTable.xmlAttributesType;
}
resultTypes = types.checkTypes(xmlAttributeAccessExpr, Lists.of(actualType), expTypes);
return;
}
checkExpr(indexExpr, env, Lists.of(symTable.stringType)).get(0);
if (indexExpr.getKind() == NodeKind.XML_QNAME) {
((BLangXMLQName) indexExpr).isUsedInXML = true;
}
if (indexExpr.type.tag == TypeTags.STRING) {
actualType = symTable.stringType;
}
xmlAttributeAccessExpr.namespaces.putAll(symResolver.resolveAllNamespaces(env));
resultTypes = types.checkTypes(xmlAttributeAccessExpr, Lists.of(actualType), expTypes);
}
Aggregations