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 BInvokableType record fields of effective types not inheriting readonly flag #43472

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading