-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42521 from Thushara-Piyasekara/fix-error-code-inc…
…onsistency Fix `BFields` of generated immutable `BRecords` not being marked as `SymbolFlags.READONLY`
- Loading branch information
Showing
6 changed files
with
114 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../resources/test-src/types/readonly/test_tuple_vs_array_readonly_violation_consistency.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/test; | ||
|
||
type Employee record {| | ||
int id; | ||
string name; | ||
|}; | ||
|
||
function testFrozenAnyArrayElementUpdate() returns error? { | ||
error? actualError = trap frozenAnyArrayElementUpdate(); | ||
test:assertTrue(actualError is error); | ||
error e = <error>actualError; | ||
test:assertEquals(e.message(), "{ballerina/lang.map}InherentTypeViolation"); | ||
test:assertEquals(e.detail()["message"], | ||
"cannot update 'readonly' field 'name' in record of type '(Employee & readonly)'"); | ||
} | ||
|
||
function frozenAnyArrayElementUpdate() returns error? { | ||
Employee e1 = {name: "Em", id: 1000}; | ||
anydata[] i1 = [e1]; | ||
anydata[] i2 = i1.cloneReadOnly(); | ||
Employee e2 = check trap <Employee>i2[0]; | ||
e2["name"] = "Zee"; | ||
return (); | ||
} | ||
|
||
function frozenTupleUpdate() { | ||
Employee e1 = {name: "Em", id: 1000}; | ||
[int, Employee] t1 = [1, e1]; | ||
[int, Employee] t2 = t1.cloneReadOnly(); | ||
Employee e2 = {name: "Zee", id: 1200}; | ||
t2[1] = e2; | ||
} |
38 changes: 38 additions & 0 deletions
38
...src/types/readonly/test_tuple_vs_array_readonly_violation_without_tuple_update_method.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
import ballerina/test; | ||
|
||
type Employee record {| | ||
int id; | ||
string name; | ||
|}; | ||
|
||
function frozenAnyArrayElementUpdate() returns error? { | ||
Employee e1 = {name: "Em", id: 1000}; | ||
anydata[] i1 = [e1]; | ||
anydata[] i2 = i1.cloneReadOnly(); | ||
Employee e2 = check trap <Employee>i2[0]; | ||
e2["name"] = "Zee"; | ||
return (); | ||
} | ||
|
||
function testFrozenAnyArrayElementUpdate() returns error? { | ||
error? actualError = trap frozenAnyArrayElementUpdate(); | ||
test:assertTrue(actualError is error); | ||
test:assertEquals((<error>actualError).message(), "{ballerina/lang.map}InherentTypeViolation"); | ||
test:assertEquals((<error>actualError).detail()["message"], | ||
"cannot update 'readonly' field 'name' in record of type 'Employee & readonly'"); | ||
} |