Code review comment: Resolving this and should be handled depending on the fix for https://github.com/ballerina-platform/ballerina-lang/issues/37097

Code before review:
public void visit(BLangObjectConstructorExpression objectCtorExpression, AnalyzerData data) {
BLangClassDefinition classNode = objectCtorExpression.classNode;
classNode.oceEnvData.capturedClosureEnv = data.env;
BLangClassDefinition originalClass = classNode.oceEnvData.originalClass;
if (originalClass.cloneRef != null && !objectCtorExpression.defined) {
classNode = (BLangClassDefinition) originalClass.cloneRef;
symbolEnter.defineClassDefinition(classNode, data.env);
objectCtorExpression.defined = true;
}
BObjectType objectType;
if (objectCtorExpression.referenceType == null && objectCtorExpression.expectedType != null) {
objectType = (BObjectType) objectCtorExpression.classNode.getBType();
BType effectiveType = Types.getEffectiveType(Types.getReferredType(objectCtorExpression.expectedType));
if (effectiveType.tag == TypeTags.OBJECT) {
BObjectType expObjType = (BObjectType) Types.getReferredType(effectiveType);
objectType.typeIdSet = expObjType.typeIdSet;
} else if (effectiveType.tag != TypeTags.NONE) {
if (!checkAndLoadTypeIdSet(objectCtorExpression.expectedType, objectType)) {
dlog.error(objectCtorExpression.pos, DiagnosticErrorCode.INVALID_TYPE_OBJECT_CONSTRUCTOR,
objectCtorExpression.expectedType);
data.resultType = symTable.semanticError;
return;
}
}
}
BLangTypeInit cIExpr = objectCtorExpression.typeInit;
BType actualType = symResolver.resolveTypeNode(cIExpr.userDefinedType, data.env);
if (actualType == symTable.semanticError) {
data.resultType = symTable.semanticError;
return;
}
BObjectType actualObjectType = (BObjectType) actualType;
List<BLangType> typeRefs = classNode.typeRefs;
SymbolEnv typeDefEnv = SymbolEnv.createObjectConstructorObjectEnv(classNode, data.env);
classNode.oceEnvData.typeInit = objectCtorExpression.typeInit;
dlog.unmute();
if (Symbols.isFlagOn(data.expType.flags, Flags.READONLY)) {
handleObjectConstrExprForReadOnly(objectCtorExpression, actualObjectType, typeDefEnv, false, data);
} else if (!typeRefs.isEmpty() && Symbols.isFlagOn(typeRefs.get(0).getBType().flags,
Flags.READONLY)) {
handleObjectConstrExprForReadOnly(objectCtorExpression, actualObjectType, typeDefEnv, true, data);
} else {
semanticAnalyzer.analyzeNode(classNode, typeDefEnv);
}
dlog.unmute();
markConstructedObjectIsolatedness(actualObjectType);
if (((BObjectTypeSymbol) actualType.tsymbol).initializerFunc != null) {
cIExpr.initInvocation.symbol = ((BObjectTypeSymbol) actualType.tsymbol).initializerFunc.symbol;
checkInvocationParam(cIExpr.initInvocation, data);
cIExpr.initInvocation.setBType(((BInvokableSymbol) cIExpr.initInvocation.symbol).retType);
} else {
if (!isValidInitInvocation(cIExpr, (BObjectType) actualType, data)) {
return;
}
}
if (cIExpr.initInvocation.getBType() == null) {
cIExpr.initInvocation.setBType(symTable.nilType);
}
BType actualTypeInitType = getObjectConstructorReturnType(actualType, cIExpr.initInvocation.getBType(), data);
data.resultType = types.checkType(cIExpr, actualTypeInitType, data.expType);
}

Line under review: BType effectiveType = Types.getEffectiveType(Types.getReferredType(objectCtorExpression.expectedType));

Code after addressing the review:
public void visit(BLangObjectConstructorExpression objectCtorExpression, AnalyzerData data) {
BLangClassDefinition classNode = objectCtorExpression.classNode;
classNode.oceEnvData.capturedClosureEnv = data.env;
BLangClassDefinition originalClass = classNode.oceEnvData.originalClass;
if (originalClass.cloneRef != null && !objectCtorExpression.defined) {
classNode = (BLangClassDefinition) originalClass.cloneRef;
symbolEnter.defineClassDefinition(classNode, data.env);
objectCtorExpression.defined = true;
}
BObjectType objectType;
if (objectCtorExpression.referenceType == null && objectCtorExpression.expectedType != null) {
objectType = (BObjectType) objectCtorExpression.classNode.getBType();
BType effectiveType = Types.getEffectiveType(Types.getReferredType(objectCtorExpression.expectedType));
if (effectiveType.tag == TypeTags.OBJECT) {
BObjectType expObjType = (BObjectType) Types.getReferredType(effectiveType);
objectType.typeIdSet = expObjType.typeIdSet;
} else if (effectiveType.tag != TypeTags.NONE) {
if (!checkAndLoadTypeIdSet(objectCtorExpression.expectedType, objectType)) {
dlog.error(objectCtorExpression.pos, DiagnosticErrorCode.INVALID_TYPE_OBJECT_CONSTRUCTOR,
objectCtorExpression.expectedType);
data.resultType = symTable.semanticError;
return;
}
}
}
BLangTypeInit cIExpr = objectCtorExpression.typeInit;
BType actualType = symResolver.resolveTypeNode(cIExpr.userDefinedType, data.env);
if (actualType == symTable.semanticError) {
data.resultType = symTable.semanticError;
return;
}
BObjectType actualObjectType = (BObjectType) actualType;
List<BLangType> typeRefs = classNode.typeRefs;
SymbolEnv typeDefEnv = SymbolEnv.createObjectConstructorObjectEnv(classNode, data.env);
classNode.oceEnvData.typeInit = objectCtorExpression.typeInit;
dlog.unmute();
if (Symbols.isFlagOn(data.expType.flags, Flags.READONLY)) {
handleObjectConstrExprForReadOnly(objectCtorExpression, actualObjectType, typeDefEnv, false, data);
} else if (!typeRefs.isEmpty() && Symbols.isFlagOn(typeRefs.get(0).getBType().flags,
Flags.READONLY)) {
handleObjectConstrExprForReadOnly(objectCtorExpression, actualObjectType, typeDefEnv, true, data);
} else {
semanticAnalyzer.analyzeNode(classNode, typeDefEnv);
}
dlog.unmute();
markConstructedObjectIsolatedness(actualObjectType);
if (((BObjectTypeSymbol) actualType.tsymbol).initializerFunc != null) {
cIExpr.initInvocation.symbol = ((BObjectTypeSymbol) actualType.tsymbol).initializerFunc.symbol;
checkInvocationParam(cIExpr.initInvocation, data);
cIExpr.initInvocation.setBType(((BInvokableSymbol) cIExpr.initInvocation.symbol).retType);
} else {
if (!isValidInitInvocation(cIExpr, (BObjectType) actualType, data)) {
return;
}
}
if (cIExpr.initInvocation.getBType() == null) {
cIExpr.initInvocation.setBType(symTable.nilType);
}
BType actualTypeInitType = getObjectConstructorReturnType(actualType, cIExpr.initInvocation.getBType(), data);
data.resultType = types.checkType(cIExpr, actualTypeInitType, data.expType);
}