Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd0d8f5

Browse files
committedNov 21, 2024·
Use referred type when creating typedesc for records
1 parent 35555f3 commit dd0d8f5

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed
 

‎bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/utils/AnnotationUtils.java

-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ public static void processAnnotations(MapValue<BString, Object> globalAnnotMap,
6363

6464
if (type.getTag() == TypeTags.TYPE_REFERENCED_TYPE_TAG) {
6565
Type impliedType = TypeUtils.getImpliedType(type);
66-
if (impliedType.getTag() == TypeTags.RECORD_TYPE_TAG) {
67-
processAnnotations(globalAnnotMap, impliedType);
68-
return;
69-
}
7066
if (isNonObjectType(impliedType.getTag())) {
7167
return;
7268
}

‎compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/JvmAnnotationsGen.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.wso2.ballerinalang.compiler.bir.codegen.split;
2020

2121
import org.ballerinalang.model.elements.PackageID;
22-
import org.ballerinalang.model.symbols.SymbolOrigin;
2322
import org.objectweb.asm.ClassWriter;
2423
import org.objectweb.asm.MethodVisitor;
2524
import org.wso2.ballerinalang.compiler.bir.codegen.BallerinaClassWriter;
@@ -128,8 +127,8 @@ private void loadAnnotations(MethodVisitor mv, String pkgName, BIRNode.BIRTypeDe
128127
jvmPackageGen.lookupGlobalVarClassName(pkgName, ANNOTATION_MAP_NAME);
129128
mv.visitFieldInsn(GETSTATIC, pkgClassName, ANNOTATION_MAP_NAME, JvmSignatures.GET_MAP_VALUE);
130129
BType type = typeDef.type;
131-
BType refType = typeDef.referenceType == null ||
132-
(type.tag == TypeTags.RECORD && typeDef.origin == SymbolOrigin.VIRTUAL) ? type : typeDef.referenceType;
130+
BType refType = typeDef.referenceType == null || type.tag == TypeTags.RECORD
131+
? type : typeDef.referenceType;
133132
jvmTypeGen.loadType(mv, refType);
134133
mv.visitMethodInsn(INVOKESTATIC, ANNOTATION_UTILS, "processAnnotations",
135134
JvmSignatures.PROCESS_ANNOTATIONS, false);

‎compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.wso2.ballerinalang.compiler.semantics.model.types.BTupleMember;
8383
import org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType;
8484
import org.wso2.ballerinalang.compiler.semantics.model.types.BType;
85+
import org.wso2.ballerinalang.compiler.semantics.model.types.BTypeReferenceType;
8586
import org.wso2.ballerinalang.compiler.semantics.model.types.BTypedescType;
8687
import org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType;
8788
import org.wso2.ballerinalang.compiler.semantics.model.types.BXMLSubType;
@@ -892,10 +893,11 @@ private void desugarConstants(BLangConstant constant, List<BLangVariable> desuga
892893
}
893894

894895
private void createTypedescVariable(BType type, Location pos) {
896+
BType finalType = type;
895897
if ((Types.getReferredType(type).tag != TypeTags.INTERSECTION && this.env.enclPkg.typeDefinitions.stream()
896898
.anyMatch(typeDef ->
897899
(Types.getReferredType(typeDef.typeNode.getBType()).tag == TypeTags.INTERSECTION) &&
898-
typeDef.symbol.name.value.equals(type.tsymbol.name.value)))) {
900+
typeDef.symbol.name.value.equals(finalType.tsymbol.name.value)))) {
899901
// This is a workaround for an issue where we create two type defs with same name for the below sample
900902
// type T1 [T1] & readonly;
901903
return;
@@ -905,6 +907,13 @@ private void createTypedescVariable(BType type, Location pos) {
905907
BType typedescType = new BTypedescType(type, symTable.typeDesc.tsymbol);
906908
BSymbol owner = this.env.scope.owner;
907909
BVarSymbol varSymbol = new BVarSymbol(0, name, owner.pkgID, typedescType, owner, pos, VIRTUAL);
910+
if (type.tag == TypeTags.TYPEREFDESC) {
911+
BType referredType = ((BTypeReferenceType) type).referredType;
912+
int tag = referredType.tag;
913+
if (tag == TypeTags.RECORD) {
914+
type = referredType;
915+
}
916+
}
908917
BLangTypedescExpr typedescExpr = ASTBuilderUtil.createTypedescExpr(pos, typedescType, type);
909918
typedescList.add(createSimpleVariableDef(pos, name.value, typedescType, typedescExpr, varSymbol));
910919
}

‎tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public void testValRefType() {
110110
public void testRefTypes() {
111111
Object returns = BRunUtil.invoke(compileResult, "testRefTypes");
112112
BMap<?, ?> foo2 = (BMap<?, ?>) returns;
113-
assertEquals(foo2.getType().getTag(), TypeTags.TYPE_REFERENCED_TYPE_TAG);
114113
assertEquals(foo2.get(StringUtils.fromString("s")).toString(), "qwerty");
115114
assertEquals(foo2.get(StringUtils.fromString("i")), 10L);
116115
assertEquals(getType(foo2.get(StringUtils.fromString("rj"))).getTag(), TypeTags.MAP_TAG);
@@ -121,8 +120,7 @@ public void testRefTypes() {
121120
assertEquals(getType(foo2.get(StringUtils.fromString("rp"))).getTag(), TypeTags.OBJECT_TYPE_TAG);
122121
assertEquals(((BObject) foo2.get(StringUtils.fromString("rp"))).get(StringUtils.fromString("name")).toString(),
123122
"John Doe");
124-
assertEquals(getType(foo2.get(StringUtils.fromString("ra"))).getTag(),
125-
TypeTags.RECORD_TYPE_TAG);
123+
assertEquals(getType(foo2.get(StringUtils.fromString("ra"))).getTag(), TypeTags.RECORD_TYPE_TAG);
126124
assertEquals(foo2.get(StringUtils.fromString("ra")).toString(), "{\"city\":\"Colombo\",\"country\":\"Sri " +
127125
"Lanka\"}");
128126
assertEquals(getType(foo2.get(StringUtils.fromString("crx"))).getTag(), TypeTags.XML_ELEMENT_TAG);

‎tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.ballerinalang.test.record;
1919

20-
import io.ballerina.runtime.api.TypeTags;
20+
import io.ballerina.runtime.api.types.TypeTags;
2121
import io.ballerina.runtime.api.utils.StringUtils;
2222
import io.ballerina.runtime.api.values.BArray;
2323
import io.ballerina.runtime.api.values.BMap;

‎tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordOptionalFieldsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.ballerinalang.test.record;
1919

20-
import io.ballerina.runtime.api.TypeTags;
20+
import io.ballerina.runtime.api.types.TypeTags;
2121
import io.ballerina.runtime.api.utils.StringUtils;
2222
import io.ballerina.runtime.api.values.BArray;
2323
import io.ballerina.runtime.api.values.BMap;

‎tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/typedesc/TypedescTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.ballerinalang.test.types.typedesc;
1818

19-
import io.ballerina.runtime.api.TypeTags;
19+
import io.ballerina.runtime.api.types.TypeTags;
2020
import io.ballerina.runtime.api.values.BArray;
2121
import io.ballerina.runtime.api.values.BTypedesc;
2222
import org.ballerinalang.test.BCompileUtil;

‎tests/jballerina-unit-test/src/test/resources/test-src/annotations/annotation_access_negative.bal

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function testRecordTypeAnnotationReadonlyValueEdit() {
4848

4949
error resError = <error> res;
5050
assertEquality("{ballerina/lang.map}InherentTypeViolation", resError.message());
51-
assertEquality("cannot update 'readonly' field 'foo' in record of type '(Annot & readonly)'",
51+
assertEquality("cannot update 'readonly' field 'foo' in record of type 'Annot & readonly'",
5252
resError.detail()["message"]);
5353
}
5454

‎tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_tuple_vs_array_readonly_violation_without_tuple_update_method.bal

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ function testFrozenAnyArrayElementUpdate() returns error? {
3434
test:assertTrue(actualError is error);
3535
test:assertEquals((<error>actualError).message(), "{ballerina/lang.map}InherentTypeViolation");
3636
test:assertEquals((<error>actualError).detail()["message"],
37-
"cannot update 'readonly' field 'name' in record of type '(Employee & readonly)'");
37+
"cannot update 'readonly' field 'name' in record of type 'Employee & readonly'");
3838
}

0 commit comments

Comments
 (0)
Please sign in to comment.