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 10 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.35%. Comparing base (4d2abe5) to head (fab7ee8).
Report is 6 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #42521      +/-   ##
============================================
+ Coverage     77.34%   77.35%   +0.01%     
- Complexity    58587    58592       +5     
============================================
  Files          3460     3460              
  Lines        219862   219860       -2     
  Branches      28914    28914              
============================================
+ Hits         170055   170077      +22     
+ Misses        40391    40368      -23     
+ Partials       9416     9415       -1     

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

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

github-actions bot commented Sep 8, 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.

@gimantha gimantha marked this pull request as draft September 10, 2024 03:34
@SasinduDilshara SasinduDilshara marked this pull request as ready for review September 10, 2024 05:45
Comment on lines +41 to +42
private CompileResult resultWithTupleUpdateMethod;
private CompileResult resultWithoutTupleUpdateMethod;
Copy link
Member

Choose a reason for hiding this comment

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

Can't the tests be merged to a single file, with different functions?

Copy link
Member

Choose a reason for hiding this comment

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

Make them local variables anyway. Add comments to say what's being tested.

Comment on lines +53 to +55
BCompileUtil.compile("test-src/types/readonly/test_tuple_vs_array_readonly_violation_consistency.bal");
resultWithoutTupleUpdateMethod = BCompileUtil.compile("test-src/types/readonly/" +
"test_tuple_vs_array_readonly_violation_consistency_without_tuple_Update_method.bal");
Copy link
Member

Choose a reason for hiding this comment

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

consistency doesn't make sense for the file name.

Comment on lines +172 to 175
expectedExceptionsMessageRegExp = "error: \\{ballerina/lang.map}InherentTypeViolation \\{\"message\":" +
"\"cannot update 'readonly' field 'name' in record of type 'Details & readonly'\".*")
public void testCreateDetails() {
BRunUtil.invoke(result, "testCreateDetails");
Copy link
Member

Choose a reason for hiding this comment

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

If the entire record is immutable, the former error is better?

Comment on lines +27 to +28
test:assertEquals((<error>actualError).message(), "{ballerina/lang.map}InherentTypeViolation");
test:assertEquals((<error>actualError).detail()["message"],
Copy link
Member

Choose a reason for hiding this comment

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

Extract <error>actualError out to a variable.

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
6 participants