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

[Bug]: The fromBalString function is not working properly for map expression #41700

Closed
TharmiganK opened this issue Nov 15, 2023 · 2 comments · Fixed by #41799
Closed

[Bug]: The fromBalString function is not working properly for map expression #41700

TharmiganK opened this issue Nov 15, 2023 · 2 comments · Fixed by #41799
Assignees
Labels
Priority/Blocker Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug

Comments

@TharmiganK
Copy link
Contributor

Description

$ Subject

Steps to Reproduce

Run the below code:

import ballerina/io;

public function main() returns error? {
    map<string> _ = {name:"John", city:"London"};

    string mapExpString = string `{name: "John", city: "London"}`;
    anydata output = check mapExpString.fromBalString();
    // Expected map: {"name":"John", "city":"London"}
    io:println(output);
}
$ bal run sample.bal

Compiling source
        tharmigan/sample1:0.1.0

Running executable

{"am":"John","cit":"London"}

Affected Version(s)

Ballerina SwanLake 2201.7.x, 2201.8.x

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Nov 15, 2023
@MaryamZi
Copy link
Member

While the output is incorrect here, I think the result should be an error here.

https://central.ballerina.io/ballerina/lang.value/latest#fromBalString

Parses and evaluates a subset of Ballerina expression syntax. The subset of Ballerina expression syntax supported is that produced by toBalString when applied to an anydata value.

The string for which this would work would have quotes in the keys.

import ballerina/io;

public function main() returns error? {
    string mapExpString = string `{"name": "John", "city": "London"}`;
    anydata output = check mapExpString.fromBalString();
    io:println(output); // {"name":"John",""city":"London"}
    io:println(output is map<anydata>); // true
}
import ballerina/io;

public function main() returns error? {
    map<string> mapValue = {name: "John", city: "London"};
    string mapValueToBalString = mapValue.toBalString();
    io:println(mapValueToBalString); // {"name":"John","city":"London"}

    anydata mapValueFromBalString = check mapValueToBalString.fromBalString();
    io:println(mapValueFromBalString is map<anydata>); // true
    io:println(mapValueFromBalString); // {"name":"John","city":"London"}
}

Copy link

github-actions bot commented Dec 7, 2023

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.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@Nadeeshan96 Nadeeshan96 added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority/Blocker Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants