Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Master] Fix compiler crashes when a union is used within multiple wait #37832

Merged
merged 34 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4050f89
Fix compiler crash when union in multiple wait
SasinduDilshara Sep 21, 2022
83a0018
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Oct 11, 2022
2cd397e
Add new diagnostic code for unsupported.alternative.wait.action
SasinduDilshara Oct 12, 2022
688817a
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Nov 3, 2022
203d6ab
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Nov 3, 2022
50f60f1
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Nov 14, 2022
b019785
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Nov 14, 2022
145f507
Merge branch 'issue-#34821' of https://github.com/SasinduDilshara/bal…
SasinduDilshara Nov 14, 2022
16d3251
Update error message for invalid future expression
SasinduDilshara Nov 14, 2022
bcacbd8
Update error message for invalid future expression
SasinduDilshara Nov 14, 2022
dcd5a13
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Nov 21, 2022
340f9e6
Refactor wait actions negative tests
SasinduDilshara Nov 22, 2022
74cdfa8
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Nov 28, 2022
1aeda14
Simplify wait action negative tests
SasinduDilshara Nov 28, 2022
596afa5
Merge branch 'issue-#34821' of https://github.com/SasinduDilshara/bal…
SasinduDilshara Nov 28, 2022
b887fe6
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Jan 11, 2023
7a2f1e0
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Mar 14, 2023
79450aa
Fix unwanted comma in DiagnosticErrorCode
SasinduDilshara Mar 15, 2023
5670ff0
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara May 15, 2023
ad18c25
Merge branch 'issue-#34821' of https://github.com/SasinduDilshara/bal…
SasinduDilshara May 15, 2023
017d4ba
Update diagnstic error code with missing separator
SasinduDilshara May 16, 2023
3309239
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara May 23, 2023
b91f512
Remove invalid compiler error properties of client
SasinduDilshara May 23, 2023
1b70428
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Jun 13, 2023
d2fd29d
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Jul 6, 2023
be5c24b
Remove unnecessary query related error codes
SasinduDilshara Jul 7, 2023
8e11173
Add tests for multiple wait actions,grouped exprs
SasinduDilshara Jul 7, 2023
893363c
Update checkBinaryBitwiseOperations method
SasinduDilshara Jul 10, 2023
3fca4a0
Rename the isBinaryBitwiseOperatorExpr method
SasinduDilshara Jul 12, 2023
345abe4
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Aug 8, 2023
54aef90
Update error codes
SasinduDilshara Aug 8, 2023
e33d075
Merge branch 'issue-#34821' of https://github.com/SasinduDilshara/bal…
SasinduDilshara Aug 8, 2023
e2ec8ce
Update diagnostic codes
SasinduDilshara Aug 9, 2023
511c87c
Merge branch 'master' of https://github.com/ballerina-platform/baller…
SasinduDilshara Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,13 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
EMPTY_REGEXP_STRING_DISALLOWED(
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
"BCS4044", "empty.regexp.string.disallowed"),
UNSUPPORTED_EMPTY_CHARACTER_CLASS(
"BCS4045", "unsupported.empty.character.class")
"BCS4045", "unsupported.empty.character.class"),
INCOMPATIBLE_QUERY_CONSTRUCT_TYPE("BCE4046", "invalid.error.query.construct.type"),
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
INCOMPATIBLE_QUERY_CONSTRUCT_MAP_TYPE("BCE4047", "invalid.error.query.construct.map.type"),
CANNOT_USE_ALTERNATE_WAIT_ACTION_WITHIN_MULTIPLE_WAIT_ACTION("BCE4048",
"cannot.use.alternate.wait.action.within.multiple.wait.action"),
EXPRESSION_OF_FUTURE_TYPE_EXPECTED("BCE4049", "future.expression.expected")
;
;

private String diagnosticId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4677,7 +4677,13 @@ private void checkTypesForRecords(BLangWaitForAllExpr waitExpr, AnalyzerData dat

for (BLangWaitForAllExpr.BLangWaitKeyValue keyVal : rhsFields) {
String key = keyVal.key.value;
if (!lhsFields.containsKey(key)) {
BLangExpression valueExpr = keyVal.valueExpr;
if (valueExpr != null && valueExpr.getKind() == NodeKind.BINARY_EXPR
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
&& ((BLangBinaryExpr) valueExpr).opKind == OperatorKind.BITWISE_OR) {
dlog.error(valueExpr.pos,
DiagnosticErrorCode.CANNOT_USE_ALTERNATE_WAIT_ACTION_WITHIN_MULTIPLE_WAIT_ACTION);
data.resultType = symTable.semanticError;
} 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 @@ -4739,7 +4745,14 @@ private void setEventualTypeForExpression(BLangExpression expression,
if (isSimpleWorkerReference(expression, data)) {
return;
}
BFutureType futureType = (BFutureType) expression.expectedType;

BType expectedType = expression.expectedType;
if (expectedType.tag != TypeTags.FUTURE) {
dlog.error(expression.pos, DiagnosticErrorCode.EXPRESSION_OF_FUTURE_TYPE_EXPECTED, expectedType);
return;
}

BFutureType futureType = (BFutureType) expectedType;
BType currentType = futureType.constraint;
if (types.containsErrorType(currentType)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1967,3 +1967,9 @@ error.empty.regexp.string.disallowed=\

error.unsupported.empty.character.class=\
empty character class disallowed

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=\
expected an expression of type ''future'', found ''{0}''
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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");
BAssertUtil.validateError(resultNegative, index++,
"incompatible types: expected 'future<string>', found 'future<int>'", 56, 22);
BAssertUtil.validateError(resultNegative, index++,
Expand Down Expand Up @@ -143,9 +142,26 @@ 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++,
"cannot use an alternate wait action within a multiple wait action", 115, 38);
BAssertUtil.validateError(resultNegative, index++,
"cannot use an alternate wait action within a multiple wait action", 116, 48);
BAssertUtil.validateError(resultNegative, index++,
"cannot use an alternate wait action within a multiple wait action", 117, 27);
BAssertUtil.validateError(resultNegative, index++,
"cannot use an alternate wait action within a multiple wait action", 117, 58);
BAssertUtil.validateError(resultNegative, index++, "expected an expression of type 'future'," +
" found '(future<(boolean|error)>|future<(boolean|error)>)'", 132, 38);
BAssertUtil.validateError(resultNegative, index++, "expected an expression of type 'future'," +
" found '(future<boolean>|future<boolean>)'", 133, 48);
BAssertUtil.validateError(resultNegative, index++, "expected an expression of type 'future'," +
" found '(future<(boolean|error)>|future<(boolean|error)>)'", 134, 27);
BAssertUtil.validateError(resultNegative, index++, "expected an expression of type 'future'," +
" found '(future<boolean>|future<boolean>)'", 134, 40);
Assert.assertEquals(resultNegative.getErrorCount(), index, "Wait actions negative test error count");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,50 @@ 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 {
return true;
}

worker Producer2 returns boolean|error {
return true;
}

worker Consumer1 returns boolean {
return false;
}

worker Consumer2 returns boolean {
return false;
}

WaitResult res = wait {producer: Producer1|Producer2, consumer: Consumer1};
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
res = wait {producer: Producer1, consumer: Consumer1|Consumer2};
res = wait {producer: Producer1|Producer2, consumer: Consumer1|Consumer2};
}

function waitActionWithInvalidType() {
worker Producer1 returns boolean|error {
return true;
}

worker Consumer1 returns boolean {
return false;
}

future<boolean|error>|future<boolean|error> x = Producer1;
future<boolean>|future<boolean> y = Consumer1;

WaitResult res = wait {producer: x, consumer: Consumer1};
res = wait {producer: Producer1, consumer: y};
res = wait {producer: x, consumer: y};
}

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