diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java index 1361db3b3697..ebbdce07f208 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java @@ -314,8 +314,8 @@ public void setTypeForcefully(Type type) { protected void populateInitialValues(BMapInitialValueEntry[] initialValues) { Map 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) { diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java index 9a2c6b1f7a23..2716d4a63c97 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java @@ -318,7 +318,8 @@ public Object[][] spreadOpFieldTests() { { "testSpreadOpInGlobalMap" }, { "testMappingConstrExprAsSpreadExpr" }, { "testSpreadFieldWithRecordTypeHavingNeverField" }, - { "testSpreadFieldWithRecordTypeHavingRestDescriptor" } + { "testSpreadFieldWithRecordTypeHavingRestDescriptor" }, + { "testSpreadFieldWithRecordTypeReference" } }; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/mappingconstructor/spread_op_field.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/mappingconstructor/spread_op_field.bal index ad1e89a00c3c..e36531597120 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/mappingconstructor/spread_op_field.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/mappingconstructor/spread_op_field.bal @@ -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;