$Subject. Happens only when query expression was used. If we assign an array directly, works fine.
Steps to Reproduce
type Complete Sub1|Sub2;
type Sub1 record {
string test;
};
type Sub2 record {
string test1;
};
public function main() returns error? {
Complete[] all = [];
Sub1[] sub1 = [{test: "test"}];
all = from Sub1 sub in sub1 select {test: sub.test};
Sub2 sub2 = {test1: "test1"};
all.push(sub2);
}
error: {ballerina/lang.array}InherentTypeViolation {"message":"incompatible types: expected 'ai_playground:Sub1', found 'ai_playground:Sub2'"}
at ballerina.lang.array.0:push(array.bal:419)
wso2.ai_playground.0:main(testz.bal:16)
Works if you use cloneWithType with query expression.
all = check (from Sub1 sub in sub1 select {test: sub.test}).cloneWithType();
Description
$Subject. Happens only when query expression was used. If we assign an array directly, works fine.
Steps to Reproduce
error: {ballerina/lang.array}InherentTypeViolation {"message":"incompatible types: expected 'ai_playground:Sub1', found 'ai_playground:Sub2'"} at ballerina.lang.array.0:push(array.bal:419) wso2.ai_playground.0:main(testz.bal:16)
Works if you use cloneWithType with query expression.
all = check (from Sub1 sub in sub1 select {test: sub.test}).cloneWithType();
Affected Version(s)
2201.8.4
OS, DB, other environment details and versions
No response
Related area
-> Compilation
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response