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

Improve uninitialised variable analysis for statements with on-fail #40971

Merged
merged 17 commits into from
Aug 15, 2023

Conversation

pcnfernando
Copy link
Member

Purpose

$subject
Fixes #38530

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@KavinduZoysa
Copy link
Contributor

import ballerina/io;
public function main() returns error? {
    int i;
    do {
        // check error("error");
        var _ = object {
            function init() {
                i = 2;
                io:println("222");
            }
        };
    } on fail {
        io:println("on fail");
    }
    io:println(i);
}

Please check this example. The expected output is not clear.

@codecov
Copy link

codecov bot commented Jul 14, 2023

Codecov Report

Patch coverage: 97.18% and project coverage change: +76.41% 🎉

Comparison is base (8a0431e) 0.00% compared to head (4f33405) 76.41%.
Report is 17 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master   #40971       +/-   ##
=============================================
+ Coverage      0.00%   76.41%   +76.41%     
- Complexity        0    52146    +52146     
=============================================
  Files             9     2858     +2849     
  Lines            35   196060   +196025     
  Branches          0    25411    +25411     
=============================================
+ Hits              0   149810   +149810     
- Misses           35    37948    +37913     
- Partials          0     8302     +8302     
Files Changed Coverage Δ
.../compiler/semantics/analyzer/DataflowAnalyzer.java 89.96% <97.18%> (ø)

... and 2856 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pcnfernando
Copy link
Member Author

pcnfernando commented Jul 14, 2023

import ballerina/io;
public function main() returns error? {
    int i;
    do {
        // check error("error");
        var _ = object {
            function init() {
                i = 2;
                io:println("222");
            }
        };
    } on fail {
        io:println("on fail");
    }
    io:println(i);
}

This is not actually related to on-fail

import ballerina/io;

public function main() returns error? {
    int i;
    var _ = object {
        function init() {
            i = 2;
            io:println("222");
        }
    };
    io:println(i); // uninint var error
}

Hence, created #41013

@pcnfernando pcnfernando added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Jul 14, 2023
@github-actions
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@gimantha gimantha merged commit 4925404 into ballerina-platform:master Aug 15, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Use of on fail can lead to use of an uninitilized variable at runtime
3 participants