Skip to content

Commit

Permalink
Add new diagnostic code for unsupported.alternative.wait.action
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Oct 26, 2022
1 parent 83a0018 commit 4818537
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>|future<boolean>)' 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<boolean>|future<boolean>)' 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");
}

Expand Down

0 comments on commit 4818537

Please sign in to comment.