Skip to content

Commit

Permalink
Merge pull request #4 from KRVPerera/issue-28248_fix_object_ctor_tests
Browse files Browse the repository at this point in the history
Fix object ctor expression test cases for function pointer PR
  • Loading branch information
chiranSachintha authored Jan 4, 2022
2 parents cc796e1 + 89f7b4d commit 6126131
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,12 @@ private void addClosureMapToInit(BLangClassDefinition classDef, BVarSymbol mapSy
// eg : $map$block$_<num2>
BLangSimpleVarRef refToBlockClosureMap = ASTBuilderUtil.createVariableRef(classDef.pos, mapSymbol);
BLangTypeInit typeInit = oceData.typeInit;
BLangInvocation initInvocation = (BLangInvocation) typeInit.initInvocation;
BLangInvocation initInvocation;
if (typeInit.initInvocation.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
initInvocation = (BLangInvocation) oceData.initInvocation;
} else {
initInvocation = (BLangInvocation) typeInit.initInvocation;
}
if (typeInit.argsExpr == null) {
typeInit.argsExpr = new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6555,17 +6555,22 @@ private BLangExpression rewriteInvocation(BLangInvocation invocation, boolean as
}
break;
}
populateOCEInvocation(invocation, invRef);
return fixTypeCastInTypeParamInvocation(invocation, invRef);
}

private void populateOCEInvocation(BLangInvocation invocation,
BLangInvocation invRef) {
if (invocation.objectInitMethod && Symbols.isFlagOn(invocation.expr.getBType().flags, Flags.OBJECT_CTOR)) {
BObjectType initializingObject = (BObjectType) invocation.expr.getBType();
BLangClassDefinition classDef = initializingObject.classDef;
if (classDef.hasClosureVars) {
OCEDynamicEnvironmentData oceEnvData = initializingObject.classDef.oceEnvData;
if (oceEnvData.attachedFunctionInvocation == null) {
oceEnvData.attachedFunctionInvocation = (BLangAttachedFunctionInvocation) result;
oceEnvData.attachedFunctionInvocation = (BLangAttachedFunctionInvocation) invRef;
}
}
}
return fixTypeCastInTypeParamInvocation(invocation, invRef);
}

private void fixNonRestArgTypeCastInTypeParamInvocation(BLangInvocation iExpr) {
Expand Down Expand Up @@ -6641,6 +6646,7 @@ private BLangStatementExpression desugarObjectTypeInit(BLangTypeInit typeInitExp

// Person $obj$ = new;
BLangInvocation initInvocation = (BLangInvocation) typeInitExpr.initInvocation;
initInvocation.objectInitMethod = true;
BType objType = getObjectType(typeInitExpr.getBType());
BLangSimpleVariableDef objVarDef = createVarDef("$obj$", objType, typeInitExpr, typeInitExpr.pos);
// var $temp$ = $obj$.init();
Expand All @@ -6658,6 +6664,12 @@ private BLangStatementExpression desugarObjectTypeInit(BLangTypeInit typeInitExp
// init() returning nil is the common case and the type test is not needed for it.
if (initInvocation.getBType().tag == TypeTags.NIL) {
initInvocation.name.value = GENERATED_INIT_SUFFIX.value;
BLangNode parent = initInvocation.parent;
if (parent.getKind() == NodeKind.OBJECT_CTOR_EXPRESSION) {
BLangObjectConstructorExpression oceExpression = (BLangObjectConstructorExpression) parent;
OCEDynamicEnvironmentData oceData = oceExpression.classNode.oceEnvData;
oceData.initInvocation = typeInitExpr.initInvocation;
}
typeInitExpr.initInvocation = objInitVarRef;
BLangStatementExpression stmtExpr = createStatementExpression(blockStmt, objVarRef);
stmtExpr.setBType(objVarRef.symbol.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.types.BObjectType;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class OCEDynamicEnvironmentData {
public boolean closureDesugaringInProgress;
public boolean isDirty;
public List<BLangSimpleVarRef> desugaredClosureVars;
public BLangExpression initInvocation;

public OCEDynamicEnvironmentData() {
lambdaFunctionsList = new ArrayList<>(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public void testCompiledConstructedObjects(String funcName) {
BRunUtil.invoke(compiledConstructedObjects, funcName);
}

@Test(dataProvider = "ClosureTestFunctionList", enabled = false)
@Test(dataProvider = "ClosureTestFunctionList")
public void testClosureSupportForObjectCtor(String funcName) {
BRunUtil.invoke(closures, funcName);
}

@Test(enabled = false)
@Test
public void testClosureSupportForObjectCtorAnnotations() {
BRunUtil.invoke(annotations, "testAnnotations");
BRunUtil.invoke(annotations, "testObjectConstructorAnnotationAttachment");
Expand Down Expand Up @@ -171,7 +171,7 @@ public Object[][] multiLevelClosureTestFunctionList() {
};
}

@Test(dataProvider = "MultiLevelClosureTestFunctionList", enabled = false)
@Test(dataProvider = "MultiLevelClosureTestFunctionList")
public void testMultiLevelClosures(String funcName) {
BRunUtil.invoke(multiLevelClosures, funcName);
}
Expand Down

0 comments on commit 6126131

Please sign in to comment.