Code review comment: For example `cannot use type inclusion with more than one open record with different rest descriptor types`

Code before review:
private void defineFieldsOfObjectOrRecordTypeDef(BLangTypeDefinition typeDef, SymbolEnv pkgEnv) {
NodeKind nodeKind = typeDef.typeNode.getKind();
if (nodeKind != NodeKind.OBJECT_TYPE && nodeKind != NodeKind.RECORD_TYPE) {
return;
}
BStructureType structureType = (BStructureType) typeDef.symbol.type;
BLangStructureTypeNode structureTypeNode = (BLangStructureTypeNode) typeDef.typeNode;
SymbolEnv typeDefEnv = SymbolEnv.createTypeEnv(structureTypeNode, typeDef.symbol.scope, pkgEnv);
resolveFields(structureType, structureTypeNode, typeDefEnv);
if (typeDef.symbol.kind != SymbolKind.RECORD) {
return;
}
BLangRecordTypeNode recordTypeNode = (BLangRecordTypeNode) structureTypeNode;
BRecordType recordType = (BRecordType) structureType;
recordType.sealed = recordTypeNode.sealed;
if (recordTypeNode.sealed && recordTypeNode.restFieldType != null) {
dlog.error(recordTypeNode.restFieldType.pos, DiagnosticErrorCode.REST_FIELD_NOT_ALLOWED_IN_SEALED_RECORDS);
return;
}
if (recordTypeNode.restFieldType != null) {
recordType.restFieldType = symResolver.resolveTypeNode(recordTypeNode.restFieldType, typeDefEnv);
return;
}
if (!recordTypeNode.sealed) {
recordType.restFieldType = symTable.anydataType;
return;
}
for (BLangType typeRef : recordTypeNode.typeRefs) {
if (typeRef.type.tag != TypeTags.RECORD) {
continue;
}
BType restFieldType = ((BRecordType) typeRef.type).restFieldType;
if (restFieldType == null || restFieldType == symTable.noType) {
continue;
}
if (recordType.restFieldType != null && recordType.restFieldType.tag != restFieldType.tag) {
recordType.restFieldType = symTable.noType;
dlog.error(recordTypeNode.pos,
DiagnosticErrorCode.CANNOT_USE_TYPE_INCLUSION_WITH_MORE_THAN_ONE_OPEN_RECORD);
return;
}
recordType.restFieldType = restFieldType;
recordType.sealed = false;
}
if (recordType.restFieldType != null) {
return;
}
recordType.restFieldType = symTable.noType;
}

Line under review: DiagnosticErrorCode.CANNOT_USE_TYPE_INCLUSION_WITH_MORE_THAN_ONE_OPEN_RECORD);

Code after addressing the review:
private void defineFieldsOfObjectOrRecordTypeDef(BLangTypeDefinition typeDef, SymbolEnv pkgEnv) {
NodeKind nodeKind = typeDef.typeNode.getKind();
if (nodeKind != NodeKind.OBJECT_TYPE && nodeKind != NodeKind.RECORD_TYPE) {
return;
}
BStructureType structureType = (BStructureType) typeDef.symbol.type;
BLangStructureTypeNode structureTypeNode = (BLangStructureTypeNode) typeDef.typeNode;
SymbolEnv typeDefEnv = SymbolEnv.createTypeEnv(structureTypeNode, typeDef.symbol.scope, pkgEnv);
resolveFields(structureType, structureTypeNode, typeDefEnv);
if (typeDef.symbol.kind != SymbolKind.RECORD) {
return;
}
BLangRecordTypeNode recordTypeNode = (BLangRecordTypeNode) structureTypeNode;
BRecordType recordType = (BRecordType) structureType;
recordType.sealed = recordTypeNode.sealed;
if (recordTypeNode.sealed && recordTypeNode.restFieldType != null) {
dlog.error(recordTypeNode.restFieldType.pos, DiagnosticErrorCode.REST_FIELD_NOT_ALLOWED_IN_SEALED_RECORDS);
return;
}
if (recordTypeNode.restFieldType != null) {
recordType.restFieldType = symResolver.resolveTypeNode(recordTypeNode.restFieldType, typeDefEnv);
return;
}
if (!recordTypeNode.sealed) {
recordType.restFieldType = symTable.anydataType;
return;
}
for (BLangType typeRef : recordTypeNode.typeRefs) {
if (typeRef.type.tag != TypeTags.RECORD) {
continue;
}
BType restFieldType = ((BRecordType) typeRef.type).restFieldType;
if (restFieldType == symTable.noType) {
continue;
}
if (recordType.restFieldType != null && !types.isSameType(recordType.restFieldType, restFieldType)) {
recordType.restFieldType = symTable.noType;
dlog.error(recordTypeNode.pos,
DiagnosticErrorCode.
CANNOT_USE_TYPE_INCLUSION_WITH_MORE_THAN_ONE_OPEN_RECORD_WITH_DIFFERENT_REST_DESCRIPTOR_TYPES);
return;
}
recordType.restFieldType = restFieldType;
recordType.sealed = false;
}
if (recordType.restFieldType != null) {
return;
}
recordType.restFieldType = symTable.noType;
}