Skip to content

Commit

Permalink
Fix effectively close records not getting detected correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Sep 10, 2024
1 parent 1a2a01d commit 39c7a3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6205,7 +6205,7 @@ public void generateFieldsForUserUnspecifiedRecordFields(BLangRecordLiteral reco
generateFieldsForUserUnspecifiedRecordFields(recordType, userSpecifiedFields, fieldNames, pos, isReadonly);
}

private static boolean isSpreadingAnOpenRecord(List<RecordLiteralNode.RecordField> userSpecifiedFields) {
private boolean isSpreadingAnOpenRecord(List<RecordLiteralNode.RecordField> userSpecifiedFields) {
for (RecordLiteralNode.RecordField field : userSpecifiedFields) {
if (!(field instanceof BLangRecordLiteral.BLangRecordSpreadOperatorField spreadOperatorField)) {
continue;
Expand All @@ -6215,7 +6215,7 @@ private static boolean isSpreadingAnOpenRecord(List<RecordLiteralNode.RecordFiel
return true;
}
if (recordType.restFieldType != null &&
Types.getImpliedType(recordType.restFieldType).tag != TypeTags.NEVER) {
!types.isNeverTypeOrStructureTypeWithARequiredNeverMember(recordType.restFieldType)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ type OuterXAlsoClosed record {|
never...;
|};

type EffectivelyCloseRecord record {|
*OuterXBase;
record {|
never bar;
|}...;
|};

isolated function testDefaultValueFromInclusion() {
Outer o = {};
OuterX ox = {...o};
Expand Down Expand Up @@ -397,6 +404,18 @@ isolated function testDefaultValueFromInclusion() {
lock {
assertEquality(5, count);
}

EffectivelyCloseRecord ecr = {...o};
assertEquality(ecr.inner.foo, 10);
lock {
assertEquality(6, count);
}

EffectivelyCloseRecord ecr1 = {...o1};
assertEquality(ecr1.inner.foo, 20);
lock {
assertEquality(6, count);
}
}

type Data record {
Expand Down

0 comments on commit 39c7a3d

Please sign in to comment.