From fe271fda39116684b3dbba412c1b43cf6bb7174a Mon Sep 17 00:00:00 2001 From: hindujaB Date: Fri, 1 Nov 2024 21:59:12 +0530 Subject: [PATCH 1/5] Use referred type for populating default values --- .../java/io/ballerina/runtime/internal/values/MapValueImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 53b0e46f92f2..2b962b3e7000 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,7 +314,7 @@ public void setTypeForcefully(Type type) { protected void populateInitialValues(BMapInitialValueEntry[] initialValues) { Map> defaultValues = new HashMap<>(); - if (type.getTag() == TypeTags.RECORD_TYPE_TAG) { + if (referredType.getTag() == TypeTags.RECORD_TYPE_TAG) { defaultValues.putAll(((BRecordType) type).getDefaultValues()); } From 8b8c9dbe50bd48a996701674cd3c6a32447072b1 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Fri, 1 Nov 2024 22:03:33 +0530 Subject: [PATCH 2/5] Fix CCE error --- .../java/io/ballerina/runtime/internal/values/MapValueImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2b962b3e7000..7fffceda5d01 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 @@ -315,7 +315,7 @@ public void setTypeForcefully(Type type) { protected void populateInitialValues(BMapInitialValueEntry[] initialValues) { Map> defaultValues = new HashMap<>(); if (referredType.getTag() == TypeTags.RECORD_TYPE_TAG) { - defaultValues.putAll(((BRecordType) type).getDefaultValues()); + defaultValues.putAll(((BRecordType) referredType).getDefaultValues()); } for (BMapInitialValueEntry initialValue : initialValues) { From ff20d73d7c26f946dae7a65daced0833869aeedc Mon Sep 17 00:00:00 2001 From: hindujaB Date: Tue, 5 Nov 2024 14:11:38 +0530 Subject: [PATCH 3/5] Add test case --- .../MappingConstructorExprTest.java | 3 ++- .../mappingconstructor/spread_op_field.bal | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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..ef79f2a07841 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..fd11b76e4c55 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.5, re.interval); + assertEquality(0.5, re.backOffFactor); + assertEquality(0, 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; From 8ca5d9c2c332970bc0c8515551c3c9631c625b7c Mon Sep 17 00:00:00 2001 From: hindujaB Date: Tue, 5 Nov 2024 14:13:44 +0530 Subject: [PATCH 4/5] Fix failing test case --- .../mappingconstructor/MappingConstructorExprTest.java | 2 +- .../expressions/mappingconstructor/spread_op_field.bal | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 ef79f2a07841..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 @@ -319,7 +319,7 @@ public Object[][] spreadOpFieldTests() { { "testMappingConstrExprAsSpreadExpr" }, { "testSpreadFieldWithRecordTypeHavingNeverField" }, { "testSpreadFieldWithRecordTypeHavingRestDescriptor" }, - {"testSpreadFieldWithRecordTypeReference"} + { "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 fd11b76e4c55..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 @@ -318,9 +318,9 @@ function testSpreadFieldWithRecordTypeReference() { RetryConfig rc = {count: 3, interval: 0.5, backOffFactor: 0.5}; RetryTyperef re = {...rc}; assertEquality(3, re.count); - assertEquality(0.5, re.interval); + assertEquality(0.5d, re.interval); assertEquality(0.5, re.backOffFactor); - assertEquality(0, re.maxWaitInterval); + assertEquality(0d, re.maxWaitInterval); assertEquality(0, re.statusCodes.length()); } From a9c44d4f6dc6828c55803425d5a50d4627c5ff18 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Thu, 21 Nov 2024 06:22:54 +0530 Subject: [PATCH 5/5] Fix master conflicts --- .../io/ballerina/runtime/internal/values/MapValueImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 8ac31edb7551..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 @@ -313,7 +313,7 @@ public void setTypeForcefully(Type type) { } protected void populateInitialValues(BMapInitialValueEntry[] initialValues) { - Map> defaultValues = new HashMap<>(); + Map defaultValues = new HashMap<>(); if (referredType.getTag() == TypeTags.RECORD_TYPE_TAG) { defaultValues.putAll(((BRecordType) referredType).getDefaultValues()); } @@ -346,9 +346,7 @@ protected void populateInitialValues(BMapInitialValueEntry[] initialValues) { @Override public void populateInitialValue(K key, V value) { - if ( - - .getTag() == TypeTags.MAP_TAG) { + if (referredType.getTag() == TypeTags.MAP_TAG) { MapUtils.handleInherentTypeViolatingMapUpdate(value, (BMapType) referredType); putValue(key, value); } else {