From 2cd397ee5ae825cdd033ec20490101fe9124cf86 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 12 Oct 2022 11:02:23 +0530 Subject: [PATCH] Add new diagnostic code for unsupported.alternative.wait.action --- .../util/diagnostic/DiagnosticErrorCode.java | 5 +++-- .../semantics/analyzer/TypeChecker.java | 10 ++++----- .../src/main/resources/compiler.properties | 7 ++++-- .../test/worker/WaitActionsNegativeTest.java | 22 +++++++------------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticErrorCode.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticErrorCode.java index 3ac8ead4b962..18e43af803b6 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticErrorCode.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticErrorCode.java @@ -795,8 +795,9 @@ public enum DiagnosticErrorCode implements DiagnosticCode { "BCE4043", "module.generated.for.client.decl.must.have.a.client.object.type"), MODULE_GENERATED_FOR_CLIENT_DECL_CANNOT_HAVE_MUTABLE_STATE( "BCE4044", "module.generated.for.client.decl.cannot.have.mutable.state"), - ALTERNATIVE_WAIT_ACTION_NOT_SUPPORTED_IN_MULTIPLE_WAIT_EXPRESSION("BCE4035", - "unsupported.alternative.wait.action.in.multiple.wait.expr") + CANNOT_USE_ALTERNATE_WAIT_ACTION_WITHIN_MULTIPLE_WAIT_ACTION("BCE4045", + "cannot.use.alternate.wait.action.within.multiple.wait.action"), + EXPRESSION_OF_FUTURE_TYPE_EXPECTED("BCE4046", "future.expression.expected") ; private String diagnosticId; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index b79d7ad91755..853bcbe4d3c5 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -4616,13 +4616,12 @@ private void checkTypesForRecords(BLangWaitForAllExpr waitExpr, AnalyzerData dat for (BLangWaitForAllExpr.BLangWaitKeyValue keyVal : rhsFields) { String key = keyVal.key.value; BLangExpression valueExpr = keyVal.valueExpr; - if (valueExpr instanceof BLangBinaryExpr + if (valueExpr != null && valueExpr.getKind() == NodeKind.BINARY_EXPR && ((BLangBinaryExpr) valueExpr).opKind == OperatorKind.BITWISE_OR) { dlog.error(valueExpr.pos, - DiagnosticErrorCode.ALTERNATIVE_WAIT_ACTION_NOT_SUPPORTED_IN_MULTIPLE_WAIT_EXPRESSION); + DiagnosticErrorCode.CANNOT_USE_ALTERNATE_WAIT_ACTION_WITHIN_MULTIPLE_WAIT_ACTION); data.resultType = symTable.semanticError; - } - else if (!lhsFields.containsKey(key)) { + } else if (!lhsFields.containsKey(key)) { // Check if the field is sealed if so you cannot have dynamic fields if (((BRecordType) Types.getReferredType(data.expType)).sealed) { dlog.error(waitExpr.pos, DiagnosticErrorCode.INVALID_FIELD_NAME_RECORD_LITERAL, key, data.expType); @@ -4685,8 +4684,7 @@ private void setEventualTypeForExpression(BLangExpression expression, return; } if (expression.expectedType.tag != TypeTags.FUTURE) { - dlog.error(expression.pos, DiagnosticErrorCode.INCOMPATIBLE_TYPE_WAIT_FUTURE_EXPR, - symTable.futureType, expression.expectedType, expression); + dlog.error(expression.pos, DiagnosticErrorCode.EXPRESSION_OF_FUTURE_TYPE_EXPECTED); return; } diff --git a/compiler/ballerina-lang/src/main/resources/compiler.properties b/compiler/ballerina-lang/src/main/resources/compiler.properties index 0d03fcf64f10..1f71a477f630 100644 --- a/compiler/ballerina-lang/src/main/resources/compiler.properties +++ b/compiler/ballerina-lang/src/main/resources/compiler.properties @@ -1954,5 +1954,8 @@ error.module.generated.for.client.decl.must.have.a.client.object.type=\ error.module.generated.for.client.decl.cannot.have.mutable.state=\ a module generated for a client declaration cannot have mutable state -error.unsupported.alternative.wait.action.in.multiple.wait.expr=\ - alternative wait action not yet support inside multiple wait expressions +error.cannot.use.alternate.wait.action.within.multiple.wait.action=\ + cannot use an alternate wait action within a multiple wait action + +error.future.expression.expected=\ + expression of future type is expected diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/worker/WaitActionsNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/worker/WaitActionsNegativeTest.java index 16eb93fc6da4..37f1ea957532 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/worker/WaitActionsNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/worker/WaitActionsNegativeTest.java @@ -146,31 +146,25 @@ public void testNegativeWorkerActions() { "incompatible types: expected 'string', found eventual type '(string|error)' for wait future " + "expression 'f4'", 90, 54); BAssertUtil.validateError(resultNegative, index++, - "alternative wait action not yet support inside multiple wait expressions", + "cannot use an alternate wait action within a multiple wait action", 123, 38); BAssertUtil.validateError(resultNegative, index++, - "alternative wait action not yet support inside multiple wait expressions", + "cannot use an alternate wait action within a multiple wait action", 124, 48); BAssertUtil.validateError(resultNegative, index++, - "alternative wait action not yet support inside multiple wait expressions", + "cannot use an alternate wait action within a multiple wait action", 125, 27); BAssertUtil.validateError(resultNegative, index++, - "alternative wait action not yet support inside multiple wait expressions", + "cannot use an alternate wait action within a multiple wait action", 125, 58); BAssertUtil.validateError(resultNegative, index++, - "incompatible types: expected 'future<(any|error)>', found eventual type " + - "'(future<(boolean|error)>|future<(boolean|error)>)' for wait" + - " future expression 'x'", 141, 38); + "expression of future type is expected", 141, 38); BAssertUtil.validateError(resultNegative, index++, - "incompatible types: expected 'future<(any|error)>', found eventual type" + - " '(future|future)' for wait future expression 'y'", 142, 48); + "expression of future type is expected", 142, 48); BAssertUtil.validateError(resultNegative, index++, - "incompatible types: expected 'future<(any|error)>', found eventual type" + - " '(future<(boolean|error)>|future<(boolean|error)>)' for" + - " wait future expression 'x'", 143, 27); + "expression of future type is expected", 143, 27); BAssertUtil.validateError(resultNegative, index++, - "incompatible types: expected 'future<(any|error)>', found eventual type" + - " '(future|future)' for wait future expression 'y'", 143, 40 ); + "expression of future type is expected", 143, 40); Assert.assertEquals(resultNegative.getErrorCount(), index, "Wait actions negative test error count"); }