Skip to content

Conversation

@iamvirul
Copy link
Contributor

Purpose

Approach

  • Updated IsolationAnalyzer to skip mutable-storage diagnostics when a record/object field default references a symbol flagged with Flags.CONFIGURABLE.
  • Added regression coverage via test-src/statements/variabledef/configurable_record_field_default.bal and a new GlobalVarTest.testConfigurableVarInRecordFieldDefaultValue, guarding the reported scenario.

Samples

  • tests/jballerina-unit-test/src/test/resources/test-src/statements/variabledef/configurable_record_field_default.bal demonstrates assigning a configurable string|string[]? to a record field default.

Remarks

  • Verified with ./gradlew :jballerina-unit-test:test --tests org.ballerinalang.test.types.globalvar.GlobalVarTest on JDK 21.

Check List

…n record and object field default values. Add unit test for configurable variable usage in record field default values.
@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.05%. Comparing base (3485c88) to head (a065e17).
⚠️ Report is 24 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #44403      +/-   ##
============================================
+ Coverage     75.02%   75.05%   +0.02%     
- Complexity    58602    58618      +16     
============================================
  Files          3600     3600              
  Lines        226681   226684       +3     
  Branches      29498    29500       +2     
============================================
+ Hits         170071   170131      +60     
+ Misses        47140    47078      -62     
- Partials       9470     9475       +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +1307 to +1310
if ((recordFieldDefaultValue || objectFieldDefaultValueRequiringIsolation) &&
Symbols.isFlagOn(flags, Flags.CONFIGURABLE)) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is the correct fix.

A configurable variable is implicitly final and immutable, so the check at L1315 should be sufficient. The issue here seems to be that the relevant flags aren't set when this check happens.

For example, the following works

configurable string|string[]? fooConfig = ();

isolated int[] x = [1, 2, 3];

function fn() returns string|string[]?  {
    lock {
        foreach var i in x {

        }
        
        // This is allowed because the flags are set by the time this check happens
        return fooConfig; 
    }
}

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.

[Bug]: Configurable Variables with Union Type Recognized as a Mutable Storage

2 participants