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]: Incorrect result when using global variable as a default value for class field and parameter #40769

Closed
chiranSachintha opened this issue Jun 20, 2023 · 1 comment · Fixed by #40774
Assignees
Labels
needTriage The issue has to be inspected and labeled manually Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Milestone

Comments

@chiranSachintha
Copy link
Member

Description

import ballerina/io;

final int recI = 111222;

class ClassWithDefaultsWithoutInitFunc {
    int i = recI;
}

function value(int k = recI) returns int {
    return k;
}

public function main() {
    ClassWithDefaultsWithoutInitFunc c1 = new;
    int k = c1.i;
    io:println(k); // prints 0 should be 111222
}

The provided code demonstrates an issue where a global variable, 'recI', is used as the default value for both a class field and a function parameter. However, the expected behavior of initializing these values with the global variable is not met. Instead, the default value is incorrectly set to 0, leading to incorrect output when running the code.

Steps to Reproduce

No response

Affected Version(s)

No response

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

@chiranSachintha chiranSachintha added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels Jun 20, 2023
@chiranSachintha chiranSachintha self-assigned this Jun 20, 2023
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Jun 20, 2023
@MaryamZi MaryamZi added this to the 2201.8.0 milestone Aug 7, 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.

@chiranSachintha chiranSachintha added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Aug 15, 2023
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 Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Projects
Archived in project
3 participants