diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/utils/AnnotationUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/utils/AnnotationUtils.java index b350bcedc14f..00b7d37b44f4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/utils/AnnotationUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/utils/AnnotationUtils.java @@ -63,10 +63,6 @@ public static void processAnnotations(MapValue globalAnnotMap, if (type.getTag() == TypeTags.TYPE_REFERENCED_TYPE_TAG) { Type impliedType = TypeUtils.getImpliedType(type); - if (impliedType.getTag() == TypeTags.RECORD_TYPE_TAG) { - processAnnotations(globalAnnotMap, impliedType); - return; - } if (isNonObjectType(impliedType.getTag())) { return; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/JvmAnnotationsGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/JvmAnnotationsGen.java index 05a5e16c0873..fb1305081f4e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/JvmAnnotationsGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/JvmAnnotationsGen.java @@ -19,7 +19,6 @@ package org.wso2.ballerinalang.compiler.bir.codegen.split; import org.ballerinalang.model.elements.PackageID; -import org.ballerinalang.model.symbols.SymbolOrigin; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; import org.wso2.ballerinalang.compiler.bir.codegen.BallerinaClassWriter; @@ -128,8 +127,8 @@ private void loadAnnotations(MethodVisitor mv, String pkgName, BIRNode.BIRTypeDe jvmPackageGen.lookupGlobalVarClassName(pkgName, ANNOTATION_MAP_NAME); mv.visitFieldInsn(GETSTATIC, pkgClassName, ANNOTATION_MAP_NAME, JvmSignatures.GET_MAP_VALUE); BType type = typeDef.type; - BType refType = typeDef.referenceType == null || - (type.tag == TypeTags.RECORD && typeDef.origin == SymbolOrigin.VIRTUAL) ? type : typeDef.referenceType; + BType refType = typeDef.referenceType == null || type.tag == TypeTags.RECORD + ? type : typeDef.referenceType; jvmTypeGen.loadType(mv, refType); mv.visitMethodInsn(INVOKESTATIC, ANNOTATION_UTILS, "processAnnotations", JvmSignatures.PROCESS_ANNOTATIONS, false); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java index 2cef9dc1cd50..b60244a23e60 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java @@ -82,6 +82,7 @@ import org.wso2.ballerinalang.compiler.semantics.model.types.BTupleMember; import org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; +import org.wso2.ballerinalang.compiler.semantics.model.types.BTypeReferenceType; import org.wso2.ballerinalang.compiler.semantics.model.types.BTypedescType; import org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType; import org.wso2.ballerinalang.compiler.semantics.model.types.BXMLSubType; @@ -892,10 +893,11 @@ private void desugarConstants(BLangConstant constant, List desuga } private void createTypedescVariable(BType type, Location pos) { + BType finalType = type; if ((Types.getReferredType(type).tag != TypeTags.INTERSECTION && this.env.enclPkg.typeDefinitions.stream() .anyMatch(typeDef -> (Types.getReferredType(typeDef.typeNode.getBType()).tag == TypeTags.INTERSECTION) && - typeDef.symbol.name.value.equals(type.tsymbol.name.value)))) { + typeDef.symbol.name.value.equals(finalType.tsymbol.name.value)))) { // This is a workaround for an issue where we create two type defs with same name for the below sample // type T1 [T1] & readonly; return; @@ -905,6 +907,13 @@ private void createTypedescVariable(BType type, Location pos) { BType typedescType = new BTypedescType(type, symTable.typeDesc.tsymbol); BSymbol owner = this.env.scope.owner; BVarSymbol varSymbol = new BVarSymbol(0, name, owner.pkgID, typedescType, owner, pos, VIRTUAL); + if (type.tag == TypeTags.TYPEREFDESC) { + BType referredType = ((BTypeReferenceType) type).referredType; + int tag = referredType.tag; + if (tag == TypeTags.RECORD) { + type = referredType; + } + } BLangTypedescExpr typedescExpr = ASTBuilderUtil.createTypedescExpr(pos, typedescType, type); typedescList.add(createSimpleVariableDef(pos, name.value, typedescType, typedescExpr, varSymbol)); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java index ab3ac52f7f42..8076caed862b 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java @@ -110,7 +110,6 @@ public void testValRefType() { public void testRefTypes() { Object returns = BRunUtil.invoke(compileResult, "testRefTypes"); BMap foo2 = (BMap) returns; - assertEquals(foo2.getType().getTag(), TypeTags.TYPE_REFERENCED_TYPE_TAG); assertEquals(foo2.get(StringUtils.fromString("s")).toString(), "qwerty"); assertEquals(foo2.get(StringUtils.fromString("i")), 10L); assertEquals(getType(foo2.get(StringUtils.fromString("rj"))).getTag(), TypeTags.MAP_TAG); @@ -121,8 +120,7 @@ public void testRefTypes() { assertEquals(getType(foo2.get(StringUtils.fromString("rp"))).getTag(), TypeTags.OBJECT_TYPE_TAG); assertEquals(((BObject) foo2.get(StringUtils.fromString("rp"))).get(StringUtils.fromString("name")).toString(), "John Doe"); - assertEquals(getType(foo2.get(StringUtils.fromString("ra"))).getTag(), - TypeTags.RECORD_TYPE_TAG); + assertEquals(getType(foo2.get(StringUtils.fromString("ra"))).getTag(), TypeTags.RECORD_TYPE_TAG); assertEquals(foo2.get(StringUtils.fromString("ra")).toString(), "{\"city\":\"Colombo\",\"country\":\"Sri " + "Lanka\"}"); assertEquals(getType(foo2.get(StringUtils.fromString("crx"))).getTag(), TypeTags.XML_ELEMENT_TAG); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java index de28957edf0b..c260e0b6c590 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java @@ -17,7 +17,7 @@ */ package org.ballerinalang.test.record; -import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordOptionalFieldsTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordOptionalFieldsTest.java index 506cf5750a56..4036bb29a908 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordOptionalFieldsTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordOptionalFieldsTest.java @@ -17,7 +17,7 @@ */ package org.ballerinalang.test.record; -import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; 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 1b2961b21ff0..8539f5558225 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 @@ -16,7 +16,7 @@ */ package org.ballerinalang.test.types.typedesc; -import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BTypedesc; import org.ballerinalang.test.BCompileUtil; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annotation_access_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annotation_access_negative.bal index 5ba6a1dec1da..c3fa341d4c0b 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annotation_access_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annotation_access_negative.bal @@ -48,7 +48,7 @@ function testRecordTypeAnnotationReadonlyValueEdit() { error resError = res; assertEquality("{ballerina/lang.map}InherentTypeViolation", resError.message()); - assertEquality("cannot update 'readonly' field 'foo' in record of type '(Annot & readonly)'", + assertEquality("cannot update 'readonly' field 'foo' in record of type 'Annot & readonly'", resError.detail()["message"]); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_tuple_vs_array_readonly_violation_without_tuple_update_method.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_tuple_vs_array_readonly_violation_without_tuple_update_method.bal index b43baf877141..b04fe3c9e75a 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_tuple_vs_array_readonly_violation_without_tuple_update_method.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_tuple_vs_array_readonly_violation_without_tuple_update_method.bal @@ -34,5 +34,5 @@ function testFrozenAnyArrayElementUpdate() returns error? { test:assertTrue(actualError is error); test:assertEquals((actualError).message(), "{ballerina/lang.map}InherentTypeViolation"); test:assertEquals((actualError).detail()["message"], - "cannot update 'readonly' field 'name' in record of type '(Employee & readonly)'"); + "cannot update 'readonly' field 'name' in record of type 'Employee & readonly'"); }