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]: Bad type on operand stack error when readonly table is returned #40376

Closed
pcnfernando opened this issue May 9, 2023 · 6 comments · Fixed by #40577
Closed

[Bug]: Bad type on operand stack error when readonly table is returned #40376

pcnfernando opened this issue May 9, 2023 · 6 comments · Fixed by #40577
Assignees
Labels
Area/JVMCodeGen JVM code generation module 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

@pcnfernando
Copy link
Member

pcnfernando commented May 9, 2023

Description

type Customer record {|
    readonly int id;
    readonly string name;
    int noOfItems;
|};

isolated table<Customer> key(id) customerTable = table [];

public function main() {
    _ = getApiKeywords();
}

isolated function getApiKeywords() returns readonly & table<Customer> key(id) {
    lock {
        return customerTable.cloneReadOnly();
    }
}

Stacktrace:

[2023-05-09 22:29:46,516] SEVERE {b7a.log.crash} - Bad type on operand stack
Exception Details:
  Location:
    test.main(Lio/ballerina/runtime/internal/scheduling/Strand;)Ljava/lang/Object; @3404: putfield
  Reason:
    Type 'java/lang/Object' (current frame, stack[2]) is not assignable to 'io/ballerina/runtime/internal/values/TableValueImpl'

Steps to Reproduce

No response

Affected Version(s)

v2201.5.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

@pcnfernando pcnfernando added Type/Bug Team/CompilerFETools Semantic API, Formatter, Shell Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. and removed Team/CompilerFETools Semantic API, Formatter, Shell labels May 9, 2023
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels May 9, 2023
@pcnfernando
Copy link
Member Author

pcnfernando commented May 9, 2023

As a workaround,

type Customer record {|
    readonly int id;
    readonly string name;
    int noOfItems;
|};

isolated table<Customer> key(id) customerTable = table [];

public function main() {
    _ = getApiKeywords();
}

isolated function getApiKeywords() returns table<Customer> key(id) {
    lock {
        return customerTable.cloneReadOnly();
    }
}

@pcnfernando
Copy link
Member Author

@pcnfernando pcnfernando changed the title [Bug]: Bad type on operand stack error when readonly table is used [Bug]: Bad type on operand stack error when readonly table is returned May 9, 2023
@pcnfernando pcnfernando added Area/JVMCodeGen JVM code generation module and removed needTriage The issue has to be inspected and labeled manually Area/JVMCodeGen JVM code generation module labels May 9, 2023
@SasinduDilshara
Copy link
Contributor

In the Desugar, the function body of the getApiKeywords() function is generated as follows.

Return: <table<(Customer & readonly)> key(id) & readonly> ballerina/lang.value:0.0.0:Cloneable $v$1 = <ballerina/lang.value:0.0.0:Cloneable> customerTable

In the Desugar, the function body of the main function is generated as follows.

BLangFunction: [PUBLIC] main ([]) (null) Body: {_ = <any> ; Return: ()}

@SasinduDilshara
Copy link
Contributor

In the Desugar, the function body of the getApiKeywords() function is generated as follows.

Return: <table<(Customer & readonly)> key(id) & readonly> ballerina/lang.value:0.0.0:Cloneable $v$1 = <ballerina/lang.value:0.0.0:Cloneable> customerTable

In the Desugar, the function body of the main function is generated as follows.

BLangFunction: [PUBLIC] main ([]) (null) Body: {_ = <any> ; Return: ()}

Seems like the return value of the getApiKeywords() function is casted into <table<(Customer & readonly)> key(id) & readonly>, which is the expected behaviour.

@SasinduDilshara
Copy link
Contributor

Had a discussion with @HindujaB and sees like the issue is having in the runtime side.
Seems like handling intersection type inside the generateFrameClassFieldUpdateByTypeTag in MethodGen is wrong.

@HindujaB HindujaB added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label May 23, 2023
@SasinduDilshara SasinduDilshara removed their assignment May 23, 2023
@HindujaB HindujaB self-assigned this May 23, 2023
@HindujaB HindujaB removed the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label May 23, 2023
@HindujaB HindujaB added the Area/JVMCodeGen JVM code generation module label Jun 2, 2023
@github-actions
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.

@HindujaB HindujaB added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Aug 10, 2023
@Nadeeshan96 Nadeeshan96 added this to the 2201.8.0 milestone Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/JVMCodeGen JVM code generation module 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.

5 participants