Skip to content

Commit

Permalink
Merge pull request #43545 from HindujaB/fix-record-field-master
Browse files Browse the repository at this point in the history
[master] Fix typecast error thrown for default record field
  • Loading branch information
gimantha authored Nov 21, 2024
2 parents a7734cb + a9c44d4 commit 2e71207
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ public void setTypeForcefully(Type type) {

protected void populateInitialValues(BMapInitialValueEntry[] initialValues) {
Map<String, BFunctionPointer> defaultValues = new HashMap<>();
if (type.getTag() == TypeTags.RECORD_TYPE_TAG) {
defaultValues.putAll(((BRecordType) type).getDefaultValues());
if (referredType.getTag() == TypeTags.RECORD_TYPE_TAG) {
defaultValues.putAll(((BRecordType) referredType).getDefaultValues());
}

for (BMapInitialValueEntry initialValue : initialValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ public Object[][] spreadOpFieldTests() {
{ "testSpreadOpInGlobalMap" },
{ "testMappingConstrExprAsSpreadExpr" },
{ "testSpreadFieldWithRecordTypeHavingNeverField" },
{ "testSpreadFieldWithRecordTypeHavingRestDescriptor" }
{ "testSpreadFieldWithRecordTypeHavingRestDescriptor" },
{ "testSpreadFieldWithRecordTypeReference" }
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,32 @@ function testSpreadFieldWithRecordTypeHavingRestDescriptor() {
assertEquality("s", r4.s);
}

type RetryConfig record {|
int count;
decimal interval;
float backOffFactor;
|};

public type RetryConfigClone record {|
int count = 0;
decimal interval = 0;
float backOffFactor = 0.0;
decimal maxWaitInterval = 0;
int[] statusCodes = [];
|};

type RetryTyperef RetryConfigClone;

function testSpreadFieldWithRecordTypeReference() {
RetryConfig rc = {count: 3, interval: 0.5, backOffFactor: 0.5};
RetryTyperef re = {...rc};
assertEquality(3, re.count);
assertEquality(0.5d, re.interval);
assertEquality(0.5, re.backOffFactor);
assertEquality(0d, re.maxWaitInterval);
assertEquality(0, re.statusCodes.length());
}

function assertEquality(any|error expected, any|error actual) {
if expected is anydata && actual is anydata && expected == actual {
return;
Expand Down

0 comments on commit 2e71207

Please sign in to comment.