-
Notifications
You must be signed in to change notification settings - Fork 755
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
[Bug]: Cannot cast spread record to record #43199
Comments
When you use a cast with a (mapping) constructor expression, the type becomes the contextually-expected type for the (mapping) constructor. So it is effectively the same as A a = {...x}; With the spread field, we look at the type of the expression used with spread - which is To do purely a cast, you can do record {} x = {"a": "a"};
record {} y = {...x};
A a = <A>y; But this will panic at runtime, since For the same reason, A b = check {...x}.ensureType(); // allowed at compile-time, but returns an error at runtime |
Oh that is a bit weird to me that the I used the following code that was suggested in the issue to convert to a custom record type: import ballerinax/salesforce;
type SalesforceCase record {|
string Id;
|};
configurable salesforce:ConnectionConfig salesforceConfig = ?;
public function main() returns error? {
salesforce:Client salesforce = check new (config = salesforceConfig);
stream<record {}, error?> caseResponse = check salesforce->query(string `
SELECT Id
FROM Case
`);
final SalesforceCase[] cases = check from record {} entry in caseResponse
select check {...entry}.ensureType();
} Is this somehow different because it is in a query expression or is this due to what |
All different examples that I'm trying always end up with the runtime error that you described. It is probably because of some "native magic" that is done here |
It probably works in the query case since the type of the constructed value comes from the select clause (related to #43006, ballerina-platform/ballerina-spec#1309). You don't even need final SalesforceCase[] cases = check from SalesforceCase entry in caseResponse
select {...entry}; This also works. Had to change SalesforceCase to be an open record either way. |
This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now. |
Description
I don't quite understand why this cast is not allowed. Is this intended or a bug?
Steps to Reproduce
No response
Affected Version(s)
Swanlake Update 9.2
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
The text was updated successfully, but these errors were encountered: