Skip to content

[Bug]:Error When Casting readonly Record Type #43999

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

Open
DimuthuMadushan opened this issue Apr 10, 2025 · 1 comment · May be fixed by #44038
Open

[Bug]:Error When Casting readonly Record Type #43999

DimuthuMadushan opened this issue Apr 10, 2025 · 1 comment · May be fixed by #44038
Assignees
Labels
needTriage The issue has to be inspected and labeled manually Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug userCategory/Compilation
Milestone

Comments

@DimuthuMadushan
Copy link
Contributor

Description

The PR #2227 includes several fixes related to lock usage and readonly types in the GraphQL module, which works in update 11. I ported these changes to the Update 12 branch, but the build fails with the following error:

error: {ballerina}TypeCastError {"message":"incompatible types: '(graphql:__Field & readonly)' cannot be cast to 'graphql:(ballerina/graphql:1:__Field & readonly)'"}
	at ballerina.graphql.1.VariableValidatorVisitor:visitField(variable_validator_visitor.bal:66)
	   ballerina.graphql.parser.1.FieldNode:accept(field_node.bal:38)
	   ballerina.graphql.1.VariableValidatorVisitor:visitOperation(variable_validator_visitor.bal:51)
	   ballerina.graphql.parser.1.OperationNode:accept(operation_node.bal:41)
	   ballerina.graphql.1.VariableValidatorVisitor:visitDocument(variable_validator_visitor.bal:40)
	   ballerina.graphql.parser.1.DocumentNode:accept(document_node.bal:29)
	   ballerina.graphql.1:$lambda$_5(engine.bal:244)

https://github.com/ballerina-platform/module-ballerina-graphql/actions/runs/14348808975/job/40223545386?pr=2227#step:5:520

The failure occurs when a readonly type record value is created on the Ballerina side(L46), parsed into a visitor, and then cast back to its original state:

readonly & __Field? schemaFieldForOperation = createSchemaFieldFromOperation(self.schema.types, operationNode, self.errors, self.nodeModifierContext);

This value is then passed into the following visitor function(L65), where the cast results in a runtime error:

public isolated function visitField(parser:FieldNode fieldNode, anydata data = ()) {
    readonly & __Field parentField = <readonly & __Field>data;
    readonly & __Type parentType = getOfType(parentField.'type);
    readonly & __Field? requiredFieldValue = getRequiredFieldFromType(parentType, self.schema.types, fieldNode);
    readonly & __InputValue[] inputValues = requiredFieldValue is __Field ? requiredFieldValue.args : [];
    self.validateDirectiveVariables(fieldNode);
    foreach parser:ArgumentNode argument in fieldNode.getArguments() {
        argument.accept(self, inputValues);
    }
    if fieldNode.getSelections().length() > 0 {
        parser:SelectionNode[] selections = fieldNode.getSelections();
        foreach parser:SelectionNode subSelection in selections {
            subSelection.accept(self, data);
        }
    }
}

Steps to Reproduce

Run this test case using following command
./gradlew build -Pgroups=query_complexity

Affected Version(s)

2201.12.0

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

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Apr 10, 2025
@ThisaruGuruge
Copy link
Member

@gimantha Can we prioritize this? Without this being fixed, we cannot port GraphQL document caching feature to the Update 12.

@ravinperera00 ravinperera00 self-assigned this Apr 17, 2025
@ravinperera00 ravinperera00 moved this from In Progress to On Hold in Ballerina Team Main Board Apr 21, 2025
@warunalakshitha warunalakshitha added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Apr 21, 2025
@ravinperera00 ravinperera00 moved this from On Hold to In Progress in Ballerina Team Main Board Apr 22, 2025
@heshanpadmasiri heshanpadmasiri linked a pull request Apr 23, 2025 that will close this issue
13 tasks
@Thevakumar-Luheerathan Thevakumar-Luheerathan added this to the 2201.12.4 milestone Apr 23, 2025
@ravinperera00 ravinperera00 moved this from In Progress to PR Sent in Ballerina Team Main Board Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needTriage The issue has to be inspected and labeled manually Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug userCategory/Compilation
Projects
Status: PR Sent
Development

Successfully merging a pull request may close this issue.

7 participants