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 BFields of generated immutable BRecords not being marked as SymbolFlags.READONLY #42521

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Thushara-Piyasekara
Copy link
Contributor

@Thushara-Piyasekara Thushara-Piyasekara commented Apr 9, 2024

Purpose

Fixes #42520

Approach

After a discussion with @heshanpadmasiri, it was apparent the InherentTypeViolation error for BFields of readonly BRecords were not getting triggered. This was due to the mutable BRecord generation not inheriting the readonly flag to the generated BFields.

After refactoring the logic to make the BFields also inherit the readonly flag, both cases mentioned in #42520 triggered the same error.

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

@Thushara-Piyasekara Thushara-Piyasekara marked this pull request as ready for review April 9, 2024 12:53
@Thushara-Piyasekara Thushara-Piyasekara marked this pull request as draft April 10, 2024 01:39
@Thushara-Piyasekara Thushara-Piyasekara force-pushed the fix-error-code-inconsistency branch 2 times, most recently from 98020f7 to a96071c Compare April 10, 2024 04:45
@Thushara-Piyasekara Thushara-Piyasekara marked this pull request as ready for review April 10, 2024 05:25
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 Apr 26, 2024
@nipunayf nipunayf removed the Stale label Apr 27, 2024
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 22, 2024
@nipunayf nipunayf removed the Stale label May 23, 2024
Copy link

github-actions bot commented Jun 7, 2024

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 7, 2024
Copy link

Closed PR due to inactivity for more than 18 days.

@github-actions github-actions bot closed this Jun 12, 2024
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.68%. Comparing base (1b17209) to head (27bcd4a).
Report is 448 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##             master   #42521    +/-   ##
==========================================
  Coverage     77.67%   77.68%            
- Complexity    51471    51474     +3     
==========================================
  Files          2933     2933            
  Lines        204124   204235   +111     
  Branches      26716    26716            
==========================================
+ Hits         158559   158654    +95     
- Misses        36938    36958    +20     
+ Partials       8627     8623     -4     

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

public void testCreateDetails() {

Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary change.

*
* @since 2201.10.0
*/
public class TupleVsArrayReadonlyErrorConsistencyTest {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to mention consistency here? I'd just include readonly field update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "consistency" keyword was added because the issue being fixed by this PR #42520 is related to an inconsistency between the errors produced during runtime.

Are you suggesting to modify the test case to match the actual bug? or is it better to use the existing real world test case?

Copy link
Member

Choose a reason for hiding this comment

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

I would just have them be part of readonly field tests. If this was the behaviour to start with, we wouldn't have had a consistency issue.

Comment on lines +46 to +51
@Test(expectedExceptions = BLangTestException.class,
expectedExceptionsMessageRegExp = "error: \\{ballerina/lang.map}InherentTypeViolation \\{\"message\":" +
"\"cannot update 'readonly' field 'name' in record of type '\\(Employee & readonly\\)'\".*")
public void testWithTupleUpdateMethod() {
BRunUtil.invoke(resultWithTupleUpdateMethod, "testFrozenAnyArrayElementUpdate");
}
Copy link
Member

Choose a reason for hiding this comment

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

We can trap the panic and do the assertion in Ballerina itself, at least for new tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shall we use this as the new test and assert the exit code from java side?

public function main() returns error? {
    error? actualError = trap testFrozenAnyArrayElementUpdate();
    if actualError is error {
        test:assertEquals(actualError.message(), "{ballerina/lang.map}InherentTypeViolation");
    }
}

Copy link
Member

Choose a reason for hiding this comment

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

The test has to fail if actualError is not an error too.

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 Stale and removed Stale labels Jul 17, 2024
Copy link

github-actions bot commented Aug 5, 2024

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 Aug 5, 2024
@nipunayf nipunayf removed the Stale label Aug 6, 2024
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]: Inconsistent runtime error messages when trying to modify a readonly record field
5 participants