ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Invalid error for readonly record field in `data.jsondata` module in `parseString` API #7302

Open SasinduDilshara opened 3 weeks ago

SasinduDilshara commented 3 weeks ago

Description

import ballerina/io;
import ballerina/data.jsondata;

type DDPerson record {|
    readonly int id;
|};

public function main() returns error? {
    string user2 = string `{"id": 4012}`;
    DDPerson r2 = check jsondata:parseString(user2);
    io:println(r2.id);
}

The above code give following error

error: {ballerina}TypeCastError {"message":"incompatible types: 'error' cannot be cast to '(anydata|data.jsondata:Error)'"}
        at ballerina.data.jsondata.0:parseString(json_api.bal:33)
           test:main(test.bal:10)

Steps to Reproduce

This is similar to the #7259 but occurs in parseString API

Version

2201.10.2

Environment Details (with versions)

No response