Code review comment: Do we need this one? we get the referredType in `public BType checkExpr(BLangExpression expr, SymbolEnv env, BType expType, DiagnosticCode diagCode) {`

Code before review:
private BType checkArrayType(BLangListConstructorExpr listConstructor, BArrayType arrayType) {
int listExprSize = 0;
if (arrayType.state != BArrayState.OPEN) {
for (BLangExpression expr : listConstructor.exprs) {
if (expr.getKind() != NodeKind.LIST_CONSTRUCTOR_SPREAD_OP) {
listExprSize++;
continue;
}
BLangExpression spreadOpExpr = ((BLangListConstructorSpreadOpExpr) expr).expr;
BType spreadOpType = checkExpr(spreadOpExpr, this.env);
spreadOpType = Types.getReferredType(spreadOpType);
switch (spreadOpType.tag) {
case TypeTags.ARRAY:
int arraySize = ((BArrayType) spreadOpType).size;
if (arraySize >= 0) {
listExprSize += arraySize;
continue;
}
dlog.error(spreadOpExpr.pos,
DiagnosticErrorCode.INVALID_SPREAD_OP_FIXED_LENGTH_LIST_EXPECTED);
return symTable.semanticError;
case TypeTags.TUPLE:
BTupleType tType = (BTupleType) spreadOpType;
if (isFixedLengthTuple(tType)) {
listExprSize += tType.tupleTypes.size();
continue;
}
dlog.error(spreadOpExpr.pos,
DiagnosticErrorCode.INVALID_SPREAD_OP_FIXED_LENGTH_LIST_EXPECTED);
return symTable.semanticError;
}
}
}
BType eType = arrayType.eType;
if (arrayType.state == BArrayState.INFERRED) {
arrayType.size = listExprSize;
arrayType.state = BArrayState.CLOSED;
} else if (arrayType.state != BArrayState.OPEN && arrayType.size != listExprSize) {
if (arrayType.size < listExprSize) {
dlog.error(listConstructor.pos, DiagnosticErrorCode.MISMATCHING_ARRAY_LITERAL_VALUES, arrayType.size,
listExprSize);
return symTable.semanticError;
}
if (!types.hasFillerValue(eType)) {
dlog.error(listConstructor.pos, DiagnosticErrorCode.INVALID_LIST_CONSTRUCTOR_ELEMENT_TYPE, expType);
return symTable.semanticError;
}
}
boolean errored = false;
for (BLangExpression expr : listConstructor.exprs) {
if (expr.getKind() != NodeKind.LIST_CONSTRUCTOR_SPREAD_OP) {
errored |= exprIncompatible(eType, expr);
continue;
}
BLangExpression spreadOpExpr = ((BLangListConstructorSpreadOpExpr) expr).expr;
BType spreadOpType = checkExpr(spreadOpExpr, this.env);
BType spreadOpReferredType = Types.getReferredType(spreadOpType);
switch (spreadOpReferredType.tag) {
case TypeTags.ARRAY:
BType spreadOpeType = ((BArrayType) spreadOpReferredType).eType;
if (types.typeIncompatible(spreadOpExpr.pos, spreadOpeType, eType)) {
return symTable.semanticError;
}
break;
case TypeTags.TUPLE:
BTupleType spreadOpTuple = (BTupleType) spreadOpReferredType;
List<BType> tupleTypes = spreadOpTuple.tupleTypes;
for (BType tupleMemberType : tupleTypes) {
if (types.typeIncompatible(spreadOpExpr.pos, tupleMemberType, eType)) {
return symTable.semanticError;
}
}
if (!isFixedLengthTuple(spreadOpTuple)) {
if (types.typeIncompatible(spreadOpExpr.pos, spreadOpTuple.restType, eType)) {
return symTable.semanticError;
}
}
break;
default:
dlog.error(spreadOpExpr.pos, DiagnosticErrorCode.INCOMPATIBLE_TYPES_LIST_SPREAD_OP, spreadOpType);
return symTable.semanticError;
}
}
return errored ? symTable.semanticError : arrayType;
}

Line under review: spreadOpType = Types.getReferredType(spreadOpType);

Code after addressing the review:
private BType checkArrayType(BLangListConstructorExpr listConstructor, BArrayType arrayType) {
int listExprSize = 0;
if (arrayType.state != BArrayState.OPEN) {
for (BLangExpression expr : listConstructor.exprs) {
if (expr.getKind() != NodeKind.LIST_CONSTRUCTOR_SPREAD_OP) {
listExprSize++;
continue;
}
BLangExpression spreadOpExpr = ((BLangListConstructorSpreadOpExpr) expr).expr;
BType spreadOpType = checkExpr(spreadOpExpr, this.env);
spreadOpType = Types.getReferredType(spreadOpType);
switch (spreadOpType.tag) {
case TypeTags.ARRAY:
int arraySize = ((BArrayType) spreadOpType).size;
if (arraySize >= 0) {
listExprSize += arraySize;
continue;
}
dlog.error(spreadOpExpr.pos,
DiagnosticErrorCode.INVALID_SPREAD_OP_FIXED_LENGTH_LIST_EXPECTED);
return symTable.semanticError;
case TypeTags.TUPLE:
BTupleType tType = (BTupleType) spreadOpType;
if (isFixedLengthTuple(tType)) {
listExprSize += tType.tupleTypes.size();
continue;
}
dlog.error(spreadOpExpr.pos,
DiagnosticErrorCode.INVALID_SPREAD_OP_FIXED_LENGTH_LIST_EXPECTED);
return symTable.semanticError;
}
}
}
BType eType = arrayType.eType;
if (arrayType.state == BArrayState.INFERRED) {
arrayType.size = listExprSize;
arrayType.state = BArrayState.CLOSED;
} else if (arrayType.state != BArrayState.OPEN && arrayType.size != listExprSize) {
if (arrayType.size < listExprSize) {
dlog.error(listConstructor.pos, DiagnosticErrorCode.MISMATCHING_ARRAY_LITERAL_VALUES, arrayType.size,
listExprSize);
return symTable.semanticError;
}
if (!types.hasFillerValue(eType)) {
dlog.error(listConstructor.pos, DiagnosticErrorCode.INVALID_LIST_CONSTRUCTOR_ELEMENT_TYPE, expType);
return symTable.semanticError;
}
}
boolean errored = false;
for (BLangExpression expr : listConstructor.exprs) {
if (expr.getKind() != NodeKind.LIST_CONSTRUCTOR_SPREAD_OP) {
errored |= exprIncompatible(eType, expr);
continue;
}
BLangExpression spreadOpExpr = ((BLangListConstructorSpreadOpExpr) expr).expr;
BType spreadOpType = checkExpr(spreadOpExpr, this.env);
BType spreadOpReferredType = Types.getReferredType(spreadOpType);
switch (spreadOpReferredType.tag) {
case TypeTags.ARRAY:
BType spreadOpeType = ((BArrayType) spreadOpReferredType).eType;
if (types.typeIncompatible(spreadOpExpr.pos, spreadOpeType, eType)) {
return symTable.semanticError;
}
break;
case TypeTags.TUPLE:
BTupleType spreadOpTuple = (BTupleType) spreadOpReferredType;
List<BType> tupleTypes = spreadOpTuple.tupleTypes;
for (BType tupleMemberType : tupleTypes) {
if (types.typeIncompatible(spreadOpExpr.pos, tupleMemberType, eType)) {
return symTable.semanticError;
}
}
if (!isFixedLengthTuple(spreadOpTuple)) {
if (types.typeIncompatible(spreadOpExpr.pos, spreadOpTuple.restType, eType)) {
return symTable.semanticError;
}
}
break;
default:
dlog.error(spreadOpExpr.pos, DiagnosticErrorCode.INCOMPATIBLE_TYPES_LIST_SPREAD_OP, spreadOpType);
return symTable.semanticError;
}
}
return errored ? symTable.semanticError : arrayType;
}