-
Notifications
You must be signed in to change notification settings - Fork 753
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]: Use of on fail
can lead to use of an uninitilized variable at runtime
#38530
Comments
We'll be taking this up on the current sprint. |
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. |
We have found a regression due to #38828. Hence reverting the fix and reopening the issue. |
Any estimate on when this may be fixed? While it may not appear as a critical bug in the type checking I do think that this is a severe issue. Especially as it can cause bugs that only appear later in the code (or not at all without proper detection). |
I agree with your comment. We are working on it atm to cover all possibilities in the data flow analysis. Please note this will be fixed on 2201.8.0 |
Description
When a variable is only initialized in a
transaction
ordo
block and errors are caught by anon fail
block ballerina will assume the variable is always initialized after theon fail
block even though the variable may not be initilized in case of an error.At runtime this will either result in a null pointer exception (the good case actually) or the use of default values (e.g. 0 for integers) which can lead to very hard to detect bugs!
Instead, the compiler should throw a compilation error for possibly undefined variables.
Steps to Reproduce
Full example code to reproduce issue (click to expand)
Affected Version(s)
Tested on Ballerina 2201.2.2 (Swan Lake Update 2) and Ballerina 2201.2.0 (Swan Lake Update 2)
OS, DB, other environment details and versions
Ubuntu in WSL 2
Language specification 2022R3
Update Tool 1.3.10
Related area
-> Compilation
Related issue(s) (optional)
Possibly related problem: #37854
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
The text was updated successfully, but these errors were encountered: