Skip to content

Commit

Permalink
Merge pull request #42582 from Thushara-Piyasekara/openhealth-readonl…
Browse files Browse the repository at this point in the history
…y-fix

Fix `BInvokableType` record fields of effective types not inheriting `readonly` flag
  • Loading branch information
gimantha authored Oct 8, 2024
2 parents b67b420 + 6f80e98 commit 0006b9d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static void populateStructureFieldsAndTypeInclusions(Types types, SymbolT
invokableSymbol.params = tsymbol.params == null ? null : new ArrayList<>(tsymbol.params);
invokableSymbol.restParam = tsymbol.restParam;
invokableSymbol.retType = tsymbol.returnType;
invokableSymbol.flags = tsymbol.flags;
invokableSymbol.flags = invokableSymbol.flags | tsymbol.flags;
} else if (fieldType == symTable.semanticError) {
// Can only happen for records.
fieldSymbol = new BVarSymbol(origField.symbol.flags | flag | Flags.OPTIONAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public void testReadonlyRecordFields(String testFunction) {
BRunUtil.invoke(result, testFunction);
}

@Test
public void testReadonlyInheritanceForInvokableTypeRecordField() {
BCompileUtil.compileAndCacheBala(
"test-src/record/cloned_record_field_flag_inheritance/imported_module_with_readonly_records");
CompileResult result = BCompileUtil.compile(
"test-src/record/cloned_record_field_flag_inheritance/module_with_field_access_for_readonly_record");
assertEquals(result.getErrorCount(), 0);
}

@DataProvider(name = "readonlyRecordFieldTestFunctions")
public Object[][] readonlyRecordFieldTestFunctions() {
return new Object[][]{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "test_org"
name = "ReadonlyRecord"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.

public type InvokableTypeDef function (int) returns int;

public type RecA record {|
readonly & InvokableTypeDef preProcessor?;
|};

public type RecB record {|
readonly RecA[] recArr;
|};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
org = "test_org"
name = "LocalPkgUsage"
version = "0.1.0"

[[dependency]]
org = "test_org"
name = "ReadonlyRecord"
version = "0.1.0"
repository="local"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 test_org/ReadonlyRecord;

ReadonlyRecord:RecB rec = {
recArr: []
};

public function main() {
ReadonlyRecord:RecA[] & readonly ops = rec.recArr;
}

0 comments on commit 0006b9d

Please sign in to comment.