Search in sources :

Example 1 with BFutureType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType in project ballerina by ballerina-lang.

the class SymbolResolver method visit.

public void visit(BLangConstrainedType constrainedTypeNode) {
    BType type = resolveTypeNode(constrainedTypeNode.type, env);
    BType constraintType = resolveTypeNode(constrainedTypeNode.constraint, env);
    if (type.tag == TypeTags.TABLE) {
        resultType = new BTableType(TypeTags.TABLE, constraintType, type.tsymbol);
    } else if (type.tag == TypeTags.STREAM) {
        resultType = new BStreamType(TypeTags.STREAM, constraintType, type.tsymbol);
    } else if (type.tag == TypeTags.FUTURE) {
        resultType = new BFutureType(TypeTags.FUTURE, constraintType, type.tsymbol);
    } else if (type.tag == TypeTags.MAP) {
        resultType = new BMapType(TypeTags.MAP, constraintType, type.tsymbol);
    } else {
        if (!types.checkStructToJSONCompatibility(constraintType) && constraintType != symTable.errType) {
            dlog.error(constrainedTypeNode.pos, DiagnosticCode.INCOMPATIBLE_TYPE_CONSTRAINT, type, constraintType);
            resultType = symTable.errType;
            return;
        }
        resultType = new BJSONType(TypeTags.JSON, constraintType, type.tsymbol);
    }
}
Also used : BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BJSONType(org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BStreamType(org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType) BFutureType(org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType)

Example 2 with BFutureType

use of org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType in project ballerina by ballerina-lang.

the class TypeChecker method visit.

public void visit(BLangAwaitExpr awaitExpr) {
    BType expType = checkExpr(awaitExpr.expr, env, Lists.of(this.symTable.futureType)).get(0);
    if (expType == symTable.errType) {
        resultTypes = Lists.of(symTable.errType);
    } else {
        BType constraint = ((BFutureType) expType).constraint;
        resultTypes = Lists.of(constraint);
        if (constraint == symTable.noType) {
            resultTypes.clear();
        }
    }
    this.checkAsyncReturnTypes(awaitExpr, resultTypes);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BFutureType(org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType)

Aggregations

BFutureType (org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)1 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)1 BStreamType (org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType)1 BTableType (org.wso2.ballerinalang.compiler.semantics.model.types.BTableType)1