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

Add compiler changes for enabling Error BP in on fail clause #40293

Merged

Conversation

suleka96
Copy link
Contributor

Purpose

Add necessary compiler changes and tests to facilitate error bp in on fail clause as a part of fixing #29183

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

@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.

@github-actions github-actions bot added the Stale label May 13, 2023
@suleka96 suleka96 removed the Stale label May 16, 2023
@codecov
Copy link

codecov bot commented May 24, 2023

Codecov Report

Patch coverage: 88.94% and project coverage change: +0.02 🎉

Comparison is base (29ba158) 77.16% compared to head (563e1d4) 77.19%.

Additional details and impacted files
@@                  Coverage Diff                   @@
##             on-fail-error-bp   #40293      +/-   ##
======================================================
+ Coverage               77.16%   77.19%   +0.02%     
- Complexity              54244    54272      +28     
======================================================
  Files                    3340     3340              
  Lines                  201659   201697      +38     
  Branches                25914    25926      +12     
======================================================
+ Hits                   155603   155690      +87     
+ Misses                  37599    37553      -46     
+ Partials                 8457     8454       -3     
Impacted Files Coverage Δ
...ina/runtime/internal/values/TypedescValueImpl.java 84.84% <ø> (ø)
...in/java/io/ballerina/cli/cmd/DeprecateCommand.java 10.76% <0.00%> (ø)
...ballerinalang/central/client/CentralAPIClient.java 44.53% <0.00%> (+0.31%) ⬆️
...allerinalang/compiler/bir/codegen/JvmValueGen.java 93.10% <ø> (ø)
...lerinalang/compiler/desugar/AnnotationDesugar.java 95.62% <ø> (ø)
.../langserver/common/constants/CommandConstants.java 90.00% <ø> (ø)
...rc/main/java/io/ballerina/cli/cmd/TestCommand.java 46.25% <33.33%> (ø)
...rinalang/langserver/hover/HoverObjectResolver.java 82.79% <50.00%> (ø)
.../main/java/io/ballerina/cli/task/RunTestsTask.java 82.59% <55.55%> (ø)
...ions/providers/context/MappingContextProvider.java 80.55% <81.25%> (ø)
... and 32 more

... and 12 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@suleka96 suleka96 marked this pull request as ready for review June 8, 2023 05:08
Comment on lines +130 to +138
testErrorCode = errCode;
testErrorReason = errReason;
testMessage = msg;
}
assertEquality(testMessage, "error!");
assertEquality(testErrorCode, 20);
assertEquality(testErrorReason, "deadlock condition");
assertEquality(testErrorCode is int, true);
assertEquality(testErrorReason is string, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use module-level variables, won't allow us to properly run these tests concurrently.

How about asserting withing the on fail block and returning there. Then outside we can have something like an assert fail to make sure control was transferred to the on fail block.

return str;
}

function testOnFailWithUnion () returns string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function testOnFailWithUnion () returns string {
function testOnFailWithUnion() returns string {


@BeforeClass
public void setup() {
programFile = BCompileUtil.compile("test-src/statements/retrystmt/retry_stmt_with_on_fail.bal");
negativeFile = BCompileUtil.compile("test-src/statements/retrystmt/retry_on_fail_negative.bal");
negativeFile1 = BCompileUtil.compile("test-src/statements/retrystmt/retry_on_fail_negative.bal");
negativeFile2 = BCompileUtil.compile("test-src/statements/retrystmt/retry_on_fail_negative_unreachable.bal");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used only in one test method, right? Use a local variable instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add licence header.

How is this file related to your changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the tests are overly complex for the errors we are trying to test. I understand that these are similar to existing tests, but not the easiest to read.

@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.

@github-actions github-actions bot added the Stale label Jun 30, 2023
@github-actions
Copy link

github-actions bot commented Jul 4, 2023

Closed PR due to inactivity for more than 18 days.

@github-actions github-actions bot closed this Jul 4, 2023
@MaryamZi MaryamZi removed the Stale label Jul 5, 2023
@MaryamZi MaryamZi reopened this Jul 5, 2023
@MaryamZi MaryamZi merged commit ff22128 into ballerina-platform:on-fail-error-bp Jul 18, 2023
@MaryamZi
Copy link
Member

Review suggestions will be addressed separately.

Need to also fix

type ErrorTypeA distinct error;

type ErrorTypeB distinct error;

function fn() {
    transaction {
        var res = checkpanic commit;
        fail error ErrorTypeA("oops!", message = "Type A");
    } on fail ErrorTypeA e {

    }
}

Fails with

ERROR [temp.bal:(9:15,9:27)] incompatible error definition type: 'error' will not be matched to 'ErrorTypeA'
ERROR [temp.bal:(9:15,9:25)] incompatible types: expected '(error|ErrorTypeA)', found 'ErrorTypeA'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants