Code review comment: Do we have tests covering this? Is this only an issue with lambda functions?

Code under review:
private void checkArrayLibSortFuncArgs(BLangInvocation iExpr) {
        if (iExpr.argExprs.size() <= 2 && !types.isOrderedType(iExpr.argExprs.get(0).type)) {
            dlog.error(iExpr.argExprs.get(0).pos, DiagnosticCode.INVALID_SORT_ARRAY_MEMBER_TYPE,
                    iExpr.argExprs.get(0).type);
        }

        if (iExpr.argExprs.size() != 3) {
            return;
        }

        BLangExpression keyFunction = iExpr.argExprs.get(2);
        BType keyFunctionType = keyFunction.type;

        if (keyFunctionType.tag == TypeTags.SEMANTIC_ERROR) {
            return;
        }

        if (keyFunctionType.tag == TypeTags.NIL) {
            if (!types.isOrderedType(iExpr.argExprs.get(0).type)) {
                dlog.error(iExpr.argExprs.get(0).pos, DiagnosticCode.INVALID_SORT_ARRAY_MEMBER_TYPE,
                        iExpr.argExprs.get(0).type);
            }
            return;
        }

        DiagnosticPos pos;
        BType returnType;

        if (keyFunction.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
            pos = keyFunction.pos;
            returnType = ((BLangSimpleVarRef) keyFunction).type.getReturnType();
        } else if (keyFunction.getKind() == NodeKind.ARROW_EXPR) {
            BLangArrowFunction arrowFunction = ((BLangArrowFunction) keyFunction);
            pos = arrowFunction.body.expr.pos;
            returnType = arrowFunction.body.expr.type;
        } else {
            BLangLambdaFunction keyLambdaFunction = (BLangLambdaFunction) keyFunction;
            pos = keyLambdaFunction.function.pos;
            returnType = keyLambdaFunction.function.type.getReturnType();
            if (returnType.tag == TypeTags.SEMANTIC_ERROR) {
                return;
            }
        }

        if (!types.isOrderedType(returnType)) {
            dlog.error(pos, DiagnosticCode.INVALID_SORT_FUNC_RETURN_TYPE, returnType);
        }
    }

Line commented on: if (returnType.tag == TypeTags.SEMANTIC_ERROR) {

Revised code:
private void checkArrayLibSortFuncArgs(BLangInvocation iExpr) {
        if (iExpr.argExprs.size() <= 2 && !types.isOrderedType(iExpr.argExprs.get(0).type)) {
            dlog.error(iExpr.argExprs.get(0).pos, DiagnosticCode.INVALID_SORT_ARRAY_MEMBER_TYPE,
                    iExpr.argExprs.get(0).type);
        }

        if (iExpr.argExprs.size() != 3) {
            return;
        }

        BLangExpression keyFunction = iExpr.argExprs.get(2);
        BType keyFunctionType = keyFunction.type;

        if (keyFunctionType.tag == TypeTags.SEMANTIC_ERROR) {
            return;
        }

        if (keyFunctionType.tag == TypeTags.NIL) {
            if (!types.isOrderedType(iExpr.argExprs.get(0).type)) {
                dlog.error(iExpr.argExprs.get(0).pos, DiagnosticCode.INVALID_SORT_ARRAY_MEMBER_TYPE,
                        iExpr.argExprs.get(0).type);
            }
            return;
        }

        DiagnosticPos pos;
        BType returnType;

        if (keyFunction.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
            pos = keyFunction.pos;
            returnType = ((BLangSimpleVarRef) keyFunction).type.getReturnType();
        } else if (keyFunction.getKind() == NodeKind.ARROW_EXPR) {
            BLangArrowFunction arrowFunction = ((BLangArrowFunction) keyFunction);
            pos = arrowFunction.body.expr.pos;
            returnType = arrowFunction.body.expr.type;
            if (returnType.tag == TypeTags.SEMANTIC_ERROR) {
                return;
            }
        } else {
            BLangLambdaFunction keyLambdaFunction = (BLangLambdaFunction) keyFunction;
            pos = keyLambdaFunction.function.pos;
            returnType = keyLambdaFunction.function.type.getReturnType();
        }

        if (!types.isOrderedType(returnType)) {
            dlog.error(pos, DiagnosticCode.INVALID_SORT_FUNC_RETURN_TYPE, returnType);
        }
    }