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

Fix issue with global variable as default value for class field and function parameter #40774

Merged

Conversation

chiranSachintha
Copy link
Member

Purpose

$title.

Fixes #40769

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

@chiranSachintha chiranSachintha added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Jun 20, 2023
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Patch coverage: 83.33% and project coverage change: +0.05% 🎉

Comparison is base (7f9a532) 76.39% compared to head (b58a604) 76.45%.
Report is 256 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #40774      +/-   ##
============================================
+ Coverage     76.39%   76.45%   +0.05%     
- Complexity    52054    52173     +119     
============================================
  Files          2857     2857              
  Lines        195858   196066     +208     
  Branches      25398    25430      +32     
============================================
+ Hits         149623   149893     +270     
+ Misses        37942    37864      -78     
- Partials       8293     8309      +16     
Files Changed Coverage Δ
...llerinalang/compiler/desugar/ClosureGenerator.java 79.19% <0.00%> (ø)
...va/io/ballerina/jsonmapper/JsonToRecordMapper.java 89.29% <100.00%> (-0.47%) ⬇️
...erina/jsonmapper/diagnostic/DiagnosticMessage.java 77.77% <100.00%> (ø)

... and 55 files with indirect coverage changes

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

@github-actions
Copy link

github-actions bot commented Jul 5, 2023

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

Comment on lines 85 to 91
function testModuleVariableReferencingClass() {
ModuleVariableReferencingClass c = new;
assertEquality(c.i, 111222);
assertEquality(c1.i, 111222);
}

function testLocalObjectConstructorReferencingModuleVariable() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we make the names uniform? They are both doing the same thing, just different constructs, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated as testClassReferencingModuleVariable and testLocalObjectConstructorReferencingModuleVariable

BRunUtil.invoke(compileResult, "testModuleVariableReferencingClass");
}

@Test
Copy link
Member

Choose a reason for hiding this comment

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

Is this the correct file for this test? Maybe both can go in org.ballerinalang.test.object.ObjectTest?

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to ObjectTest

@MaryamZi MaryamZi added this to the 2201.8.0 milestone Aug 7, 2023
@@ -47,11 +47,14 @@ public class ObjectTest {

private CompileResult checkInInitializerResult;
private CompileResult checkFunctionReferencesResult;
private CompileResult checkObjectWithDefaultableFieldsResult;
Copy link
Member

Choose a reason for hiding this comment

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

Field with default value. Or just object with default values.

Copy link
Member Author

Choose a reason for hiding this comment

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

change as checkObjectWithDefaultValuesResult


const ASSERTION_ERROR_REASON = "AssertionError";

function assertEquality(any expected, any actual) {
Copy link
Member

Choose a reason for hiding this comment

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

Why any and not anydata?

@@ -941,6 +942,16 @@ public void testNonPublicSymbolsWarningInServiceClass() {
Assert.assertEquals(result.getDiagnostics().length, 0);
}

@Test
public void testClassWithModuleDefaultValue() {
Copy link
Member

Choose a reason for hiding this comment

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

What does module default value mean?

Suggested change
public void testClassWithModuleDefaultValue() {
public void testClassWithModuleLevelVarAsDefaultValue() {

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated. I am trying to specify this test case using a module variable as a default value.

const ASSERTION_ERROR_REASON = "AssertionError";

function assertEquality(anydata expected, anydata actual) {
if expected is anydata && actual is anydata && expected == actual {
Copy link
Member

Choose a reason for hiding this comment

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

Don't you get warnings for the checks now? Always true?

Copy link
Member

Choose a reason for hiding this comment

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

Please update the logic, removing unnecessary checks.

Copy link
Member Author

Choose a reason for hiding this comment

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

didn't get the warning.

Copy link
Member

Choose a reason for hiding this comment

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

Hint rather. Didn't you get unnecessary condition: expression will always evaluate to 'true'?

@chiranSachintha chiranSachintha merged commit 8c04b7b 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]: Incorrect result when using global variable as a default value for class field and parameter
2 participants