Code review comment: Shall we extract `(BLangSimpleVarRef) size` also to a variable?

Code under review:
public void visit(BLangArrayType arrayTypeNode) {
        
        
        resultType = resolveTypeNode(arrayTypeNode.elemtype, env, diagCode);
        if (resultType == symTable.noType) {
            return;
        }
        for (int i = 0; i < arrayTypeNode.dimensions; i++) {
            BTypeSymbol arrayTypeSymbol = Symbols.createTypeSymbol(SymTag.ARRAY_TYPE, Flags.PUBLIC, Names.EMPTY,
                                                                   env.enclPkg.symbol.pkgID, null, env.scope.owner);
            BArrayType arrType;
            if (arrayTypeNode.sizes.length == 0) {
                arrType = new BArrayType(resultType, arrayTypeSymbol);
                arrayTypeSymbol.type = arrType;
                markParameterizedType(arrType, arrType.eType);
                resultType = arrayTypeSymbol.type;
            } else {
                BLangExpression size = arrayTypeNode.sizes[i];
                if (size instanceof BLangLiteral) {
                    arrType = ((Integer) (((BLangLiteral) size).getValue()) == UNSEALED_ARRAY_INDICATOR) ?
                            new BArrayType(resultType, arrayTypeSymbol,
                                    (Integer) (((BLangLiteral) size).getValue()),
                                    BArrayState.UNSEALED) :
                            ((Integer) (((BLangLiteral) size).getValue()) == OPEN_SEALED_ARRAY_INDICATOR) ?
                                    new BArrayType(resultType, arrayTypeSymbol,
                                            (Integer) (((BLangLiteral) size).getValue()),
                                            BArrayState.OPEN_SEALED) :
                                    new BArrayType(resultType, arrayTypeSymbol,
                                            (Integer) (((BLangLiteral) size).getValue()),
                                            BArrayState.CLOSED_SEALED);
                    arrayTypeSymbol.type = arrType;
                    markParameterizedType(arrType, arrType.eType);
                    resultType = arrayTypeSymbol.type;

                } else {
                    Name pkgAlias = names.fromIdNode(((BLangSimpleVarRef) size).pkgAlias);
                    Name typeName = names.fromIdNode(((BLangSimpleVarRef) size).variableName);

                    BSymbol sizeSymbol = lookupMainSpaceSymbolInPackage(size.pos, env, pkgAlias, typeName);

                    if (!(symTable.notFoundSymbol.equals(sizeSymbol))) {
                        if (sizeSymbol.tag == SymTag.CONSTANT) {
                            BType lengthLiteralType = ((BConstantSymbol) sizeSymbol).literalType;
                            if (lengthLiteralType.tag == TypeTags.INT) {
                                long length = (long) ((BConstantSymbol) sizeSymbol).value.value;
                                arrType = new BArrayType(resultType, arrayTypeSymbol,
                                        (int) length,
                                        BArrayState.CLOSED_SEALED);
                                arrayTypeSymbol.type = arrType;
                                markParameterizedType(arrType, arrType.eType);
                                resultType = arrayTypeSymbol.type;

                            } else {
                                dlog.error(arrayTypeNode.pos,
                                        DiagnosticCode.INVALID_ARRAY_SIZE_REFERENCE_TYPE,
                                        ((BConstantSymbol) sizeSymbol).literalType);
                                resultType = symTable.semanticError;
                            }
                        } else {
                            dlog.error(arrayTypeNode.pos, DiagnosticCode.INVALID_ARRAY_SIZE_REFERENCE, sizeSymbol);
                            resultType = symTable.semanticError;
                        }
                    } else {
                        dlog.error(arrayTypeNode.pos, DiagnosticCode.ARRAY_SIZE_REFERENCE_NOT_DEFINED, size);
                        resultType = symTable.semanticError;
                    }
                }
            }
        }
    }

Line commented on: Name pkgAlias = names.fromIdNode(((BLangSimpleVarRef) size).pkgAlias);

Revised code:
public void visit(BLangArrayType arrayTypeNode) {
        
        
        resultType = resolveTypeNode(arrayTypeNode.elemtype, env, diagCode);
        if (resultType == symTable.noType) {
            return;
        }
        boolean isError = false;
        for (int i = 0; i < arrayTypeNode.dimensions; i++) {
            BTypeSymbol arrayTypeSymbol = Symbols.createTypeSymbol(SymTag.ARRAY_TYPE, Flags.PUBLIC, Names.EMPTY,
                                                                   env.enclPkg.symbol.pkgID, null, env.scope.owner,
                                                                   arrayTypeNode.pos, SOURCE);
            BArrayType arrType;
            if (arrayTypeNode.sizes.length == 0) {
                arrType = new BArrayType(resultType, arrayTypeSymbol);
            } else {
                BLangExpression size = arrayTypeNode.sizes[i];
                if (size.getKind() == NodeKind.LITERAL || size.getKind() == NodeKind.NUMERIC_LITERAL) {
                    Integer sizeIndicator = (Integer) (((BLangLiteral) size).getValue());
                    BArrayState arrayState;
                    if (sizeIndicator == OPEN_ARRAY_INDICATOR) {
                        arrayState = BArrayState.UNSEALED;
                    } else if (sizeIndicator == INFERRED_ARRAY_INDICATOR) {
                        arrayState = BArrayState.OPEN_SEALED;
                    } else {
                        arrayState = BArrayState.CLOSED_SEALED;
                    }
                    arrType =  new BArrayType(resultType, arrayTypeSymbol,  sizeIndicator, arrayState);
                } else {
                    if (size.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
                        dlog.error(size.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.intType,
                                ((BLangTypedescExpr) size).getTypeNode());
                        isError = true;
                        continue;
                    }

                    BLangSimpleVarRef sizeReference = (BLangSimpleVarRef) size;
                    Name pkgAlias = names.fromIdNode(sizeReference.pkgAlias);
                    Name typeName = names.fromIdNode(sizeReference.variableName);

                    BSymbol sizeSymbol = lookupMainSpaceSymbolInPackage(size.pos, env, pkgAlias, typeName);

                    if (symTable.notFoundSymbol == sizeSymbol) {
                        dlog.error(arrayTypeNode.pos, DiagnosticCode.UNDEFINED_SYMBOL, size);
                        isError = true;
                        continue;
                    }

                    if (sizeSymbol.tag != SymTag.CONSTANT) {
                        dlog.error(size.pos, DiagnosticCode.INVALID_ARRAY_SIZE_REFERENCE, sizeSymbol);
                        isError = true;
                        continue;
                    }

                    BConstantSymbol sizeConstSymbol = (BConstantSymbol) sizeSymbol;
                    BType lengthLiteralType = sizeConstSymbol.literalType;

                    if (lengthLiteralType.tag != TypeTags.INT) {
                        dlog.error(size.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.intType,
                                sizeConstSymbol.literalType);
                        isError = true;
                        continue;
                    }

                    int length = Integer.parseInt(sizeConstSymbol.type.toString());
                    arrType = new BArrayType(resultType, arrayTypeSymbol, length, BArrayState.CLOSED_SEALED);
                }
            }
            arrayTypeSymbol.type = arrType;
            resultType = arrayTypeSymbol.type;
            markParameterizedType(arrType, arrType.eType);
        }
        if (isError) {
            resultType = symTable.semanticError;
        }
    }