Skip to content

Commit

Permalink
Fix conflicts in TypeChecker.java
Browse files Browse the repository at this point in the history
  • Loading branch information
gimantha committed Nov 14, 2022
2 parents 4d368f8 + 8a2031c commit 2d2f331
Show file tree
Hide file tree
Showing 70 changed files with 1,810 additions and 751 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public void visit(BLangClientDeclaration clientDeclNode) {

@Override
public void visit(BLangFunction funcNode) {
lookupNodes(funcNode.annAttachments);
// Compare the target lookup pos with the function symbol pos to ensure that we are not looking for the
// container of the function.
if (!this.range.equals(funcNode.symbol.pos.lineRange())) {
Expand Down Expand Up @@ -704,6 +705,7 @@ public void visit(BLangTernaryExpr ternaryExpr) {
@Override
public void visit(BLangWaitExpr awaitExpr) {
lookupNodes(awaitExpr.exprList);
setEnclosingNode(awaitExpr, awaitExpr.pos);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,10 @@ public void visit(BLangClassDefinition classDefinition) {
lookupNodes(classDefinition.fields);
lookupNodes(classDefinition.referencedFields);
lookupNode(classDefinition.initFunction);
for (BLangFunction method : classDefinition.functions) {
lookupNodes(method.annAttachments);
}

lookupNodes(classDefinition.functions);
lookupNodes(classDefinition.typeRefs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import io.ballerina.compiler.syntax.tree.SimpleNameReferenceNode;
import io.ballerina.compiler.syntax.tree.SpecificFieldNode;
import io.ballerina.compiler.syntax.tree.SpreadFieldNode;
import io.ballerina.compiler.syntax.tree.StartActionNode;
import io.ballerina.compiler.syntax.tree.TableConstructorExpressionNode;
import io.ballerina.compiler.syntax.tree.TemplateExpressionNode;
import io.ballerina.compiler.syntax.tree.Token;
Expand All @@ -89,6 +90,7 @@
import io.ballerina.compiler.syntax.tree.TypeofExpressionNode;
import io.ballerina.compiler.syntax.tree.UnaryExpressionNode;
import io.ballerina.compiler.syntax.tree.VariableDeclarationNode;
import io.ballerina.compiler.syntax.tree.WaitActionNode;
import io.ballerina.compiler.syntax.tree.WildcardBindingPatternNode;
import io.ballerina.compiler.syntax.tree.XMLFilterExpressionNode;
import io.ballerina.compiler.syntax.tree.XMLNamespaceDeclarationNode;
Expand Down Expand Up @@ -246,6 +248,16 @@ public Optional<Location> transform(SimpleNameReferenceNode simpleNameReferenceN
return simpleNameReferenceNode.name().apply(this);
}

@Override
public Optional<Location> transform(StartActionNode startActionNode) {
return Optional.of(startActionNode.location());
}

@Override
public Optional<Location> transform(WaitActionNode waitActionNode) {
return Optional.of(waitActionNode.location());
}

@Override
public Optional<Location> transform(TypeDefinitionNode typeDefinitionNode) {
return typeDefinitionNode.typeName().apply(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,9 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
CANNOT_IMPORT_MODULE_GENERATED_FOR_CLIENT_DECL(
"BCE4045", "cannot.import.module.generated.for.a.client.decl"),
CANNOT_INFER_TYPEDESC_ARGUMENT_WITHOUT_CET("BCE4046",
"cannot.infer.typedesc.argument.without.cet");
"cannot.infer.typedesc.argument.without.cet"),
OUTER_JOIN_MUST_BE_DECLARED_WITH_VAR(
"BCE4047", "outer.join.must.be.declared.with.var")
;

private String diagnosticId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3191,8 +3191,7 @@ protected BLangWhile createRetryWhileLoop(Location pos,

BLangDo retryDo = wrapStatementWithinDo(pos, retryBody, internalOnFail);

BLangTypeTestExpr isErrorCheck = createTypeCheckExpr(pos, retryResultRef,
getErrorTypeNode());
BLangTypeTestExpr isErrorCheck = createTypeCheckExpr(pos, retryResultRef, getErrorTypeNode());
BLangBinaryExpr shouldRetryCheck = ASTBuilderUtil.createBinaryExpr(pos, isErrorCheck, shouldRetryRef,
symTable.booleanType, OperatorKind.AND, null);
BLangGroupExpr rhsCheck = new BLangGroupExpr();
Expand Down Expand Up @@ -3380,9 +3379,10 @@ protected BLangNode createExpressionStatement(Location location,
}
}

protected void createErrorReturn(Location pos, BlockNode blockStmt, BLangSimpleVarRef resultRef) {
void failFastForErrorResult(Location pos, BlockNode blockStmt, BLangTypeTestExpr typeTestExpr,
BLangExpression resultRef) {
BLangIf returnError = ASTBuilderUtil.createIfStmt(pos, blockStmt);
returnError.expr = createTypeCheckExpr(pos, resultRef, getErrorTypeNode());
returnError.expr = typeTestExpr;
returnError.body = ASTBuilderUtil.createBlockStmt(pos);
BLangFail failExpressionNode = (BLangFail) TreeBuilder.createFailNode();
failExpressionNode.expr = addConversionExprIfRequired(resultRef, symTable.errorType);
Expand Down Expand Up @@ -7249,11 +7249,8 @@ private BLangStatementExpression createStmtExprForNullableBinaryExpr(BLangBinary
BLangSimpleVarRef rhsVarRef = ASTBuilderUtil.createVariableRef(binaryExpr.pos, rhsVarDef.var.symbol);
blockStmt.addStatement(rhsVarDef);

BLangTypeTestExpr typeTestExprOne = createTypeCheckExpr(binaryExpr.pos, lhsVarRef, getNillTypeNode());
typeTestExprOne.setBType(symTable.booleanType);

BLangTypeTestExpr typeTestExprTwo = createTypeCheckExpr(binaryExpr.pos, rhsVarRef, getNillTypeNode());
typeTestExprTwo.setBType(symTable.booleanType);
BLangTypeTestExpr typeTestExprOne = getNilTypeTestExpr(binaryExpr.pos, lhsVarRef);
BLangTypeTestExpr typeTestExprTwo = getNilTypeTestExpr(binaryExpr.pos, rhsVarRef);

BLangBinaryExpr ifBlockCondition = ASTBuilderUtil.createBinaryExpr(binaryExpr.pos, typeTestExprOne,
typeTestExprTwo, symTable.booleanType, OperatorKind.OR, binaryExpr.opSymbol);
Expand Down Expand Up @@ -7284,6 +7281,10 @@ private BLangStatementExpression createStmtExprForNullableBinaryExpr(BLangBinary
return stmtExpr;
}

BLangTypeTestExpr getNilTypeTestExpr(Location pos, BLangExpression expr) {
return createTypeCheckExpr(pos, expr, getNillTypeNode());
}

private BType getBinaryExprOperandNonNilType(BType operandType) {
return operandType.isNullable() ? types.getSafeType(operandType, true, false) : operandType;
}
Expand Down Expand Up @@ -7542,8 +7543,8 @@ public void visit(BLangElvisExpr elvisExpr) {
BLangBlockStmt elseBody = ASTBuilderUtil.createBlockStmt(pos);
elseBody.addStatement(notNilAssignment);

BLangIf ifStmt = ASTBuilderUtil.createIfElseStmt(pos,
createTypeCheckExpr(pos, lhsResultVarRef, getNillTypeNode()), ifBody, elseBody);
BLangIf ifStmt = ASTBuilderUtil.createIfElseStmt(pos, getNilTypeTestExpr(pos, lhsResultVarRef),
ifBody, elseBody);
BLangBlockStmt blockStmt = ASTBuilderUtil.createBlockStmt(pos, new ArrayList<>() {{
add(resultVarDef);
add(lhsResultVarDef);
Expand Down Expand Up @@ -7649,9 +7650,7 @@ private BLangStatementExpression createStmtExprForNilableUnaryExpr(BLangUnaryExp

blockStmt.addStatement(tempVarDef);

BLangTypeTestExpr typeTestExpr = createTypeCheckExpr(unaryExpr.pos, unaryExpr.expr,
getNillTypeNode());
typeTestExpr.setBType(symTable.booleanType);
BLangTypeTestExpr typeTestExpr = getNilTypeTestExpr(unaryExpr.pos, unaryExpr.expr);

BLangBlockStmt ifBody = ASTBuilderUtil.createBlockStmt(unaryExpr.pos);
BLangAssignment bLangAssignmentIf = ASTBuilderUtil.createAssignmentStmt(unaryExpr.pos, ifBody);
Expand Down Expand Up @@ -10083,7 +10082,7 @@ private BLangBinaryExpr getModifiedIntRangeEndExpr(BLangExpression expr) {
symTable.intType));
}

private BLangLiteral getBooleanLiteral(boolean value) {
BLangLiteral getBooleanLiteral(boolean value) {
BLangLiteral literal = (BLangLiteral) TreeBuilder.createLiteralExpression();
literal.value = value;
literal.setBType(symTable.booleanType);
Expand Down
Loading

0 comments on commit 2d2f331

Please sign in to comment.