Skip to content

Commit

Permalink
Fix compiler crash when union in multiple wait
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Sep 21, 2022
1 parent 00388bb commit aaea061
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4648,6 +4648,12 @@ private void setEventualTypeForExpression(BLangExpression expression,
if (isSimpleWorkerReference(expression, data)) {
return;
}
if (expression.expectedType.tag != TypeTags.FUTURE) {
dlog.error(expression.pos, DiagnosticErrorCode.INCOMPATIBLE_TYPE_WAIT_FUTURE_EXPR,
symTable.futureType, expression.expectedType, expression);
return;
}

BFutureType futureType = (BFutureType) expression.expectedType;
BType currentType = futureType.constraint;
if (types.containsErrorType(currentType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class WaitActionsNegativeTest {
public void testNegativeWorkerActions() {
CompileResult resultNegative = BCompileUtil.compile("test-src/workers/wait-actions-negative.bal");
int index = 0;
Assert.assertEquals(resultNegative.getErrorCount(), 45, "Wait actions negative test error count");
Assert.assertEquals(resultNegative.getErrorCount(), 49, "Wait actions negative test error count");
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'future<string>', found 'future<int>'", 56, 22);
BAssertUtil.validateError(resultNegative, index++,
Expand Down Expand Up @@ -143,9 +143,25 @@ public void testNegativeWorkerActions() {
"expression 'f2'", 90, 45);
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'future<string>', found 'future<(int|error)>'", 90, 54);
BAssertUtil.validateError(resultNegative, index,
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'string', found eventual type '(string|error)' for wait future " +
"expression 'f4'", 90, 54);
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'future<(any|error)>', found eventual type " +
"'(future<(boolean|error)>|future<(boolean|error)>)' for wait future expression " +
"'Producer1 | Producer2'", 123, 38);
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'future<(any|error)>', found eventual type " +
"'(future<boolean>|future<boolean>)' for wait future expression " +
"'Consumer1 | Consumer2'", 124, 48);
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'future<(any|error)>', found eventual type " +
"'(future<(boolean|error)>|future<(boolean|error)>)' for wait future expression " +
"'Producer1 | Producer2'", 125, 27);
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'future<(any|error)>', found eventual type " +
"'(future<boolean>|future<boolean>)' for wait future expression " +
"'Consumer1 | Consumer2'", 125, 58);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,41 @@ function waitForAllTest() {
restRec2 result16 = wait {id: f1, name: f2, age: f4};
}

type WaitResult record {|
boolean|error producer;
boolean consumer;
|};

function waitForAllTest2() {
worker Producer1 returns boolean|error {
int i = 100;
i -> Consumer;
error? unionResult = flush Consumer1;
return true;
}

worker Producer2 returns boolean|error {
int i = 100;
i -> Consumer;
error? unionResult = flush Consumer1;
return true;
}

worker Consumer1 returns boolean {
int i = <- Producer;
return false;
}

worker Consumer2 returns boolean {
int i = <- Producer;
return false;
}

WaitResult res = wait {producer: Producer1|Producer2, consumer: Consumer1};
res = wait {producer: Producer1, consumer: Consumer1|Consumer2};
res = wait {producer: Producer1|Producer2, consumer: Consumer1|Consumer2};
}

function print(string str) {
string result = str.toUpperAscii();
}
Expand Down

0 comments on commit aaea061

Please sign in to comment.