diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java index 796a2515f180..bad08c1c3aa3 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java @@ -22,6 +22,8 @@ import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.semtype.BasicTypeBitSet; import io.ballerina.runtime.api.types.semtype.Builder; +import io.ballerina.runtime.api.types.semtype.Context; +import io.ballerina.runtime.api.types.semtype.SemType; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BInitialValueEntry; import io.ballerina.runtime.api.values.BLink; @@ -34,6 +36,7 @@ import io.ballerina.runtime.internal.types.BTypedescType; import java.util.Map; +import java.util.Optional; import static io.ballerina.runtime.api.utils.TypeUtils.getImpliedType; @@ -160,4 +163,9 @@ public BTypedesc getTypedesc() { public Object frozenCopy(Map refs) { return this; } + + @Override + public Optional inherentTypeOf(Context cx) { + return Optional.of(SemType.tryInto(cx, getType())); + } } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/typedesc/TypedescTests.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/typedesc/TypedescTests.java index 8539f5558225..aafcf1be9ddc 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/typedesc/TypedescTests.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/typedesc/TypedescTests.java @@ -82,6 +82,11 @@ public void testBasicTypes() { Assert.assertEquals(returns.get(4).toString(), "typedesc byte"); } + @Test(description = "Test type desc shapes") + public void testTypeDescShape() { + BRunUtil.invoke(result, "testRecordWithTypedescField"); + } + @Test(description = "Test buildin ref types") public void testRefTypes() { BRunUtil.invoke(result, "testRefTypes"); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/typedesc/typedesc_positive.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/typedesc/typedesc_positive.bal index 3466fef75971..0d63860d55cd 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/typedesc/typedesc_positive.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/typedesc/typedesc_positive.bal @@ -300,6 +300,24 @@ function testTypeDefWithFunctionTypeDescAsTypedesc() { assertEquality("typedesc function () returns (string)", d.toString()); } +type TD1 record { + readonly int foo; + readonly typedesc entity; +}; + +type TD2 record { + 10 foo; + typedesc<10> entity; +}; + +function testRecordWithTypedescField() { + int foo = 10; + typedesc typeOfFoo = typeof foo; + TD1 td1 = {foo, entity: typeOfFoo}; + assertEquality(td1 is TD2, true); +} + + const ASSERTION_ERROR_REASON = "AssertionError"; function assertEquality(any|error expected, any|error actual) {