Code review comment: But it should. Even the `tsymbol.type` can be a reference type eg ```ballerina type Foo int; type Bar Foo;  public function foo() returns Bar {   return 1; } ```

Code under review:
private void checkForExportableType(BTypeSymbol symbol, Location pos, HashSet<BTypeSymbol> visitedSymbols) {

        if (symbol == null || symbol.type == null || Symbols.isFlagOn(symbol.flags, Flags.TYPE_PARAM)) {
            
            return;
        }
        if (!visitedSymbols.add(symbol)) {
            return;
        }
        BType symbolType = Types.getReferredType(symbol.type);
        switch (symbolType.tag) {
            case TypeTags.ARRAY:
                checkForExportableType(((BArrayType) symbolType).eType.tsymbol, pos, visitedSymbols);
                return;
            case TypeTags.TUPLE:
                BTupleType tupleType = (BTupleType) symbolType;
                tupleType.tupleTypes.forEach(t -> checkForExportableType(t.tsymbol, pos, visitedSymbols));
                if (tupleType.restType != null) {
                    checkForExportableType(tupleType.restType.tsymbol, pos, visitedSymbols);
                }
                return;
            case TypeTags.MAP:
                checkForExportableType(((BMapType) symbolType).constraint.tsymbol, pos, visitedSymbols);
                return;
            case TypeTags.RECORD:
                if (Symbols.isFlagOn(symbol.flags, Flags.ANONYMOUS)) {
                    BRecordType recordType = (BRecordType) symbolType;
                    recordType.fields.values().forEach(f -> checkForExportableType(f.type.tsymbol, pos,
                            visitedSymbols));
                    if (recordType.restFieldType != null) {
                        checkForExportableType(recordType.restFieldType.tsymbol, pos, visitedSymbols);
                    }
                    return;
                }
                break;
            case TypeTags.TABLE:
                BTableType tableType = (BTableType) symbolType;
                if (tableType.constraint != null) {
                    checkForExportableType(tableType.constraint.tsymbol, pos, visitedSymbols);
                }
                return;
            case TypeTags.STREAM:
                BStreamType streamType = (BStreamType) symbolType;
                if (streamType.constraint != null) {
                    checkForExportableType(streamType.constraint.tsymbol, pos, visitedSymbols);
                }
                return;
            case TypeTags.INVOKABLE:
                BInvokableType invokableType = (BInvokableType) symbolType;
                if (Symbols.isFlagOn(invokableType.flags, Flags.ANY_FUNCTION)) {
                    return;
                }
                if (invokableType.paramTypes != null) {
                    for (BType paramType : invokableType.paramTypes) {
                        checkForExportableType(paramType.tsymbol, pos, visitedSymbols);
                    }
                }
                if (invokableType.restType != null) {
                    checkForExportableType(invokableType.restType.tsymbol, pos, visitedSymbols);
                }
                checkForExportableType(invokableType.retType.tsymbol, pos, visitedSymbols);
                return;
            case TypeTags.PARAMETERIZED_TYPE:
                BTypeSymbol parameterizedType = ((BParameterizedType) symbolType).paramValueType.tsymbol;
                checkForExportableType(parameterizedType, pos, visitedSymbols);
                return;
            case TypeTags.ERROR:
                if (Symbols.isFlagOn(symbol.flags, Flags.ANONYMOUS)) {
                    checkForExportableType((((BErrorType) symbolType).detailType.tsymbol), pos, visitedSymbols);
                    return;
                }
            
        }
        if (!Symbols.isPublic(symbol)) {
            dlog.warning(pos, DiagnosticWarningCode.ATTEMPT_EXPOSE_NON_PUBLIC_SYMBOL, symbol.name);
        }
    }

Line commented on: checkForExportableType((((BErrorType) symbolType).detailType.tsymbol), pos, visitedSymbols);

Revised code:
private void checkForExportableType(BTypeSymbol symbol, Location pos, HashSet<BTypeSymbol> visitedSymbols) {

        if (symbol == null || symbol.type == null || Symbols.isFlagOn(symbol.flags, Flags.TYPE_PARAM)) {
            
            return;
        }
        if (!visitedSymbols.add(symbol)) {
            return;
        }
        BType symbolType = symbol.type;
        switch (symbolType.tag) {
            case TypeTags.ARRAY:
                checkForExportableType(((BArrayType) symbolType).eType.tsymbol, pos, visitedSymbols);
                return;
            case TypeTags.TUPLE:
                BTupleType tupleType = (BTupleType) symbolType;
                tupleType.tupleTypes.forEach(t -> checkForExportableType(t.tsymbol, pos, visitedSymbols));
                if (tupleType.restType != null) {
                    checkForExportableType(tupleType.restType.tsymbol, pos, visitedSymbols);
                }
                return;
            case TypeTags.MAP:
                checkForExportableType(((BMapType) symbolType).constraint.tsymbol, pos, visitedSymbols);
                return;
            case TypeTags.RECORD:
                if (Symbols.isFlagOn(symbol.flags, Flags.ANONYMOUS)) {
                    BRecordType recordType = (BRecordType) symbolType;
                    recordType.fields.values().forEach(f -> checkForExportableType(f.type.tsymbol, pos,
                            visitedSymbols));
                    if (recordType.restFieldType != null) {
                        checkForExportableType(recordType.restFieldType.tsymbol, pos, visitedSymbols);
                    }
                    return;
                }
                break;
            case TypeTags.TABLE:
                BTableType tableType = (BTableType) symbolType;
                if (tableType.constraint != null) {
                    checkForExportableType(tableType.constraint.tsymbol, pos, visitedSymbols);
                }
                return;
            case TypeTags.STREAM:
                BStreamType streamType = (BStreamType) symbolType;
                if (streamType.constraint != null) {
                    checkForExportableType(streamType.constraint.tsymbol, pos, visitedSymbols);
                }
                return;
            case TypeTags.INVOKABLE:
                BInvokableType invokableType = (BInvokableType) symbolType;
                if (Symbols.isFlagOn(invokableType.flags, Flags.ANY_FUNCTION)) {
                    return;
                }
                if (invokableType.paramTypes != null) {
                    for (BType paramType : invokableType.paramTypes) {
                        checkForExportableType(paramType.tsymbol, pos, visitedSymbols);
                    }
                }
                if (invokableType.restType != null) {
                    checkForExportableType(invokableType.restType.tsymbol, pos, visitedSymbols);
                }
                checkForExportableType(invokableType.retType.tsymbol, pos, visitedSymbols);
                return;
            case TypeTags.PARAMETERIZED_TYPE:
                BTypeSymbol parameterizedType = ((BParameterizedType) symbolType).paramValueType.tsymbol;
                checkForExportableType(parameterizedType, pos, visitedSymbols);
                return;
            case TypeTags.ERROR:
                if (Symbols.isFlagOn(symbol.flags, Flags.ANONYMOUS)) {
                    checkForExportableType((((BErrorType) symbolType).detailType.tsymbol), pos, visitedSymbols);
                    return;
                }
                break;
            case TypeTags.TYPEREFDESC:
                symbolType = Types.getReferredType(symbolType);
                checkForExportableType(symbolType.tsymbol, pos, visitedSymbols);
                return;
            
        }
        if (!Symbols.isPublic(symbol)) {
            dlog.warning(pos, DiagnosticWarningCode.ATTEMPT_EXPOSE_NON_PUBLIC_SYMBOL, symbol.name);
        }
    }