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 put method does not handle hash-collided keys #41723

Closed
nipunayf opened this issue Nov 19, 2023 · 1 comment · Fixed by #41960
Closed

[Bug]: The put method does not handle hash-collided keys #41723

nipunayf opened this issue Nov 19, 2023 · 1 comment · Fixed by #41960
Assignees
Labels
Area/Compiler Lang/Table Type `table` related issues 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 userCategory/Compilation
Milestone

Comments

@nipunayf
Copy link
Contributor

Description

The current implementation of the put method in the table language library does not handle the case when there are two distinct keys with the same hash code. For instance, the output of the following code is [{"k":"10"},{"k":5},{"k":0},{"k":-31},{"k":100.05},{"k":30}] when it should be [{"k":"10"},{"k":5},{"k":null},{"k":0},{"k":-31},{"k":100.05},{"k":30}].

import ballerina/io;

public function main() {
    table<record {readonly int|string|float? k;}> key(k) tbl1 = table [{k: "10"}];

    tbl1.put({k: 5});
    tbl1.put({k: ()});
    tbl1.put({k: -31});
    tbl1.put({k: 0});
    tbl1.put({k: 100.05});
    tbl1.put({k: 30});

    io:println(tbl1);
}

However, the add method of the table language library works as expected. For instance, the following code generates the expected result.

import ballerina/io;

public function main() {
    table<record {readonly int|string|float? k;}> key(k) tbl1 = table [{k: "10"}];

    tbl1.add({k: 5});
    tbl1.add({k: ()});
    tbl1.add({k: -31});
    tbl1.add({k: 0});
    tbl1.add({k: 100.05});
    tbl1.add({k: 30});

    io:println(tbl1);
}

Steps to Reproduce

Run the following Ballerina code.

import ballerina/io;

public function main() {
    table<record {readonly int|string|float? k;}> key(k) tbl1 = table [{k: "10"}];

    tbl1.put({k: 5});
    tbl1.put({k: ()});
    tbl1.put({k: -31});
    tbl1.put({k: 0});
    tbl1.put({k: 100.05});
    tbl1.put({k: 30});

    io:println(tbl1);
}

Affected Version(s)

Ballerina 2201.8.1 (Swan Lake Update 8)

OS, DB, other environment details and versions

OS: macOS 14.0 23A344
Java: openjdk version "17.0.8" 2023-07-18

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@nipunayf nipunayf added Type/Bug Lang/Table Type `table` related issues labels Nov 19, 2023
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Nov 19, 2023
@nipunayf nipunayf added Area/Compiler and removed needTriage The issue has to be inspected and labeled manually labels Nov 19, 2023
@nipunayf nipunayf added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Dec 17, 2023
@nipunayf nipunayf self-assigned this Jan 9, 2024
@nipunayf nipunayf added this to the 2201.9.0 milestone Mar 20, 2024
@github-project-automation github-project-automation bot moved this from PR Sent to Done in Ballerina Team Main Board Mar 20, 2024
Copy link

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.

@KavinduZoysa KavinduZoysa added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Compiler Lang/Table Type `table` related issues 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 userCategory/Compilation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants