diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java index 7e38f4fa3c5e..78b1cbfd58a1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java @@ -94,7 +94,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.SIMPLE_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STREAM_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRING_VALUE; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE_IMPL; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TYPEDESC_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TYPE_CHECKER; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TYPE_CONVERTER; @@ -1361,7 +1361,7 @@ static String getTargetClass(BType targetType) { targetTypeClass = MAP_VALUE; break; case TypeTags.TABLE: - targetTypeClass = TABLE_VALUE_IMPL; + targetTypeClass = TABLE_VALUE; break; case TypeTags.STREAM: targetTypeClass = STREAM_VALUE; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java index 348e077b588c..7f8d0a9edcfa 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java @@ -122,7 +122,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_RUNTIME; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STRAND_METADATA; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STREAM_VALUE; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE_IMPL; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPEDESC; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_XML; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.HANDLE_DESCRIPTOR_FOR_STRING_CONCAT; @@ -144,7 +144,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_MAP_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_REGEX_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_STREAM_VALUE; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_TABLE_VALUE_IMPL; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_TABLE_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_TYPEDESC_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_XML_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.STRING_BUILDER_APPEND; @@ -243,7 +243,7 @@ public static String getFieldTypeSignature(BType bType) { case TypeTags.STREAM: return GET_STREAM_VALUE; case TypeTags.TABLE: - return GET_TABLE_VALUE_IMPL; + return GET_TABLE_VALUE; case TypeTags.ARRAY: case TypeTags.TUPLE: return GET_ARRAY_VALUE; @@ -434,7 +434,7 @@ public static String getArgTypeSignature(BType bType) { case TypeTags.STREAM: return GET_STREAM_VALUE; case TypeTags.TABLE: - return GET_TABLE_VALUE_IMPL; + return GET_TABLE_VALUE; case TypeTags.INVOKABLE: return GET_FUNCTION_POINTER; case TypeTags.TYPEDESC: @@ -489,7 +489,7 @@ public static String generateReturnType(BType bType) { case TypeTags.STREAM: return RETURN_STREAM_VALUE; case TypeTags.TABLE: - return RETURN_TABLE_VALUE_IMPL; + return RETURN_TABLE_VALUE; case TypeTags.FUTURE: return RETURN_FUTURE_VALUE; case TypeTags.TYPEDESC: diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmSignatures.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmSignatures.java index d2968e8cbe49..340615545b3f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmSignatures.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmSignatures.java @@ -110,7 +110,6 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRING_TYPE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRING_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE_IMPL; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.THROWABLE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TOML_DETAILS; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TRANSACTION_CONTEXT_CLASS; @@ -253,7 +252,7 @@ public class JvmSignatures { public static final String GET_STRING = "L" + STRING_VALUE + ";"; public static final String GET_STRING_AT = "(L" + B_STRING_VALUE + ";J)L" + B_STRING_VALUE + ";"; public static final String GET_STRING_FROM_ARRAY = "(J)L" + OBJECT + ";"; - public static final String GET_TABLE_VALUE_IMPL = "L" + TABLE_VALUE_IMPL + ";"; + public static final String GET_TABLE_VALUE = "L" + TABLE_VALUE + ";"; public static final String GET_THROWABLE = "L" + THROWABLE + ";"; public static final String GET_TUPLE_TYPE_IMPL = "L" + TUPLE_TYPE_IMPL + ";"; public static final String GET_TYPE = "L" + TYPE + ";"; @@ -418,7 +417,7 @@ public class JvmSignatures { public static final String RETURN_MAP_VALUE = ")L" + MAP_VALUE + ";"; public static final String RETURN_OBJECT = "()L" + OBJECT + ";"; public static final String RETURN_STREAM_VALUE = ")L" + STREAM_VALUE + ";"; - public static final String RETURN_TABLE_VALUE_IMPL = ")L" + TABLE_VALUE_IMPL + ";"; + public static final String RETURN_TABLE_VALUE = ")L" + TABLE_VALUE + ";"; public static final String RETURN_TYPEDESC_VALUE = ")L" + TYPEDESC_VALUE + ";"; public static final String RETURN_XML_VALUE = ")L" + XML_VALUE + ";"; public static final String SCHEDULE_LOCAL = "([L" + OBJECT + ";L" + B_FUNCTION_POINTER + ";L" + diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java index 8853854d17fa..1cb3ec4f75e3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java @@ -144,7 +144,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_OBJECT; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_REGEXP; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STREAM_VALUE; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE_IMPL; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPEDESC; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPE_REF_TYPE_IMPL; @@ -1086,7 +1086,7 @@ public static String getTypeDesc(BType bType) { case TypeTags.STREAM: return GET_STREAM_VALUE; case TypeTags.TABLE: - return GET_TABLE_VALUE_IMPL; + return GET_TABLE_VALUE; case TypeTags.DECIMAL: return GET_BDECIMAL; case TypeTags.OBJECT: diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java index 71bb4438b6e1..c090b1c360a2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java @@ -132,7 +132,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STRAND; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STREAM_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STRING; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE_IMPL; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPEDESC; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_XML; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.INITIAL_METHOD_DESC; @@ -716,8 +716,7 @@ private void generateFrameClassFieldLoadByTypeTag(MethodVisitor mv, String frame mv.visitVarInsn(DSTORE, index); break; case TypeTags.DECIMAL: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_BDECIMAL); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_BDECIMAL); mv.visitVarInsn(ASTORE, index); break; case TypeTags.BOOLEAN: @@ -726,49 +725,40 @@ private void generateFrameClassFieldLoadByTypeTag(MethodVisitor mv, String frame break; case TypeTags.MAP: case TypeTags.RECORD: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_MAP_VALUE); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_MAP_VALUE); mv.visitVarInsn(ASTORE, index); break; case TypeTags.STREAM: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_STREAM_VALUE); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_STREAM_VALUE); mv.visitVarInsn(ASTORE, index); break; case TypeTags.TABLE: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_TABLE_VALUE_IMPL); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_TABLE_VALUE); mv.visitVarInsn(ASTORE, index); break; case TypeTags.ARRAY: case TypeTags.TUPLE: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_ARRAY_VALUE); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_ARRAY_VALUE); mv.visitVarInsn(ASTORE, index); break; case TypeTags.OBJECT: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_BOBJECT); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_BOBJECT); mv.visitVarInsn(ASTORE, index); break; case TypeTags.ERROR: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_ERROR_VALUE); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_ERROR_VALUE); mv.visitVarInsn(ASTORE, index); break; case TypeTags.FUTURE: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_FUTURE_VALUE); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_FUTURE_VALUE); mv.visitVarInsn(ASTORE, index); break; case TypeTags.INVOKABLE: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_FUNCTION_POINTER); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_FUNCTION_POINTER); mv.visitVarInsn(ASTORE, index); break; case TypeTags.TYPEDESC: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_TYPEDESC); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_TYPEDESC); mv.visitVarInsn(ASTORE, index); break; case TypeTags.NIL: @@ -780,13 +770,11 @@ private void generateFrameClassFieldLoadByTypeTag(MethodVisitor mv, String frame case TypeTags.JSON: case TypeTags.FINITE: case TypeTags.READONLY: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_OBJECT); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_OBJECT); mv.visitVarInsn(ASTORE, index); break; case TypeTags.HANDLE: - mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, - GET_HANDLE_VALUE); + mv.visitFieldInsn(GETFIELD, frameName, localVar.jvmVarName, GET_HANDLE_VALUE); mv.visitVarInsn(ASTORE, index); break; case JTypeTags.JTYPE: @@ -856,16 +844,13 @@ private void generateFrameClassFieldUpdate(List localVars, Metho mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, "J"); } else if (TypeTags.isStringTypeTag(bType.tag)) { mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_BSTRING); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_BSTRING); } else if (TypeTags.isXMLTypeTag(bType.tag)) { mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_XML); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_XML); } else if (TypeTags.REGEXP == bType.tag) { mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_REGEXP); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_REGEXP); } else { generateFrameClassFieldUpdateByTypeTag(mv, frameName, localVar, index, bType); } @@ -895,50 +880,41 @@ private void generateFrameClassFieldUpdateByTypeTag(MethodVisitor mv, String fra case TypeTags.MAP: case TypeTags.RECORD: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_MAP_VALUE); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_MAP_VALUE); break; case TypeTags.STREAM: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_STREAM_VALUE); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_STREAM_VALUE); break; case TypeTags.TABLE: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_TABLE_VALUE_IMPL); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_TABLE_VALUE); break; case TypeTags.ARRAY: case TypeTags.TUPLE: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_ARRAY_VALUE); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_ARRAY_VALUE); break; case TypeTags.ERROR: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_ERROR_VALUE); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_ERROR_VALUE); break; case TypeTags.FUTURE: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_FUTURE_VALUE); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_FUTURE_VALUE); break; case TypeTags.TYPEDESC: mv.visitVarInsn(ALOAD, index); mv.visitTypeInsn(CHECKCAST, TYPEDESC_VALUE); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_TYPEDESC); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_TYPEDESC); break; case TypeTags.OBJECT: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_BOBJECT); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_BOBJECT); break; case TypeTags.INVOKABLE: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_FUNCTION_POINTER); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_FUNCTION_POINTER); break; case TypeTags.NIL: case TypeTags.NEVER: @@ -950,13 +926,11 @@ private void generateFrameClassFieldUpdateByTypeTag(MethodVisitor mv, String fra case TypeTags.FINITE: case TypeTags.READONLY: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_OBJECT); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_OBJECT); break; case TypeTags.HANDLE: mv.visitVarInsn(ALOAD, index); - mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, - GET_HANDLE_VALUE); + mv.visitFieldInsn(PUTFIELD, frameName, localVar.jvmVarName, GET_HANDLE_VALUE); break; case JTypeTags.JTYPE: generateFrameClassJFieldUpdate(localVar, mv, index, frameName); @@ -966,8 +940,7 @@ private void generateFrameClassFieldUpdateByTypeTag(MethodVisitor mv, String fra ((BTypeReferenceType) bType).referredType); break; default: - throw new BLangCompilerException(JvmConstants.TYPE_NOT_SUPPORTED_MESSAGE + - bType); + throw new BLangCompilerException(JvmConstants.TYPE_NOT_SUPPORTED_MESSAGE + bType); } } @@ -1122,7 +1095,7 @@ private String getJVMTypeSign(BType bType) { jvmType = GET_STREAM_VALUE; break; case TypeTags.TABLE: - jvmType = GET_TABLE_VALUE_IMPL; + jvmType = GET_TABLE_VALUE; break; case TypeTags.ARRAY: case TypeTags.TUPLE: diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/table/TableValueAssignTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/table/TableValueAssignTest.java index f399fe188c42..c1ee9e42ce51 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/table/TableValueAssignTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/table/TableValueAssignTest.java @@ -53,7 +53,8 @@ public Object[] dataToTestAssignTableValue() { "testAssignKeylessTableValueToAny", "testAssignKeylessTableValueToVar", "testAssignKeylessTableValueToTableType", - "testTableVlueAssignmentToAny" + "testTableValueAssignmentToAny", + "testTableValueReturnFromFunction" }; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/table/table_value_assign_test.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/table/table_value_assign_test.bal index 1dc583552846..c89a386d877e 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/table/table_value_assign_test.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/table/table_value_assign_test.bal @@ -32,7 +32,10 @@ function testAssignKeyedTableValueToAnydata() { assertEqual(a1, a2); assertEqual(tbl1, a2); - assertEqual(isEqual(table key(name) [{name: "Amy", id: 1234}, {name: "John", id: 4567}], a2), true); + assertEqual(isEqual(table key(name) [ + {name: "Amy", id: 1234}, + {name: "John", id: 4567} + ], a2), true); } function isEqual(anydata tabl1, anydata table2) returns boolean { @@ -53,7 +56,10 @@ function testAssignKeyedTableValueToAny() { assertEqual(a1, a2); assertEqual(tbl1, a2); - var tbl2 = table key(name) [{name: "Amy", id: 1234}, {name: "John", id: 4567}]; + var tbl2 = table key(name) [ + {name: "Amy", id: 1234}, + {name: "John", id: 4567} + ]; assertEqual(tbl2, a2); } @@ -68,10 +74,14 @@ function testAssignKeyedTableValueToVar() { {name: "John", id: 4567} ]; - var ids = from var {id} in tbl1 select {id}; - table a3 = ids; + var ids = from var {id} in tbl1 + select {id}; + table a3 = ids; - var a4 = table [{"id": 1234}, {"id": 4567}]; + var a4 = table [ + {"id": 1234}, + {"id": 4567} + ]; assertEqual(a1, a2); assertEqual(tbl1, a2); @@ -84,10 +94,17 @@ function testAssignKeyedTableValueToTableType() { {name: "Amy", id: 1234}, {name: "John", id: 4567} ]; - var a2 = checkpanic table key(id) from var {id} in tbl1 select {id}; - table key(id) a3 = a2; - var a4 = table key(id) [{"id": 1234}, {"id": 4567}]; - var tbl = table key(id) [{"id": 1234}, {"id": 4567}]; + var a2 = checkpanic table key(id) from var {id} in tbl1 + select {id}; + table key(id) a3 = a2; + var a4 = table key(id) [ + {"id": 1234}, + {"id": 4567} + ]; + var tbl = table key(id) [ + {"id": 1234}, + {"id": 4567} + ]; assertEqual(tbl, a3); assertEqual(a3, a4); } @@ -105,7 +122,10 @@ function testAssignKeylessTableValueToAnydata() { assertEqual(a1, a2); assertEqual(tbl1, a2); - assertEqual(isEqual(table [{name: "Amy", id: 1234}, {name: "John", id: 4567}], a2), true); + assertEqual(isEqual(table [ + {name: "Amy", id: 1234}, + {name: "John", id: 4567} + ], a2), true); } function testAssignKeylessTableValueToAny() { @@ -119,7 +139,10 @@ function testAssignKeylessTableValueToAny() { {name: "John", id: 4567} ]; - var a3 = table [{name: "Amy", id: 1234}, {name: "John", id: 4567}]; + var a3 = table [ + {name: "Amy", id: 1234}, + {name: "John", id: 4567} + ]; assertEqual(a1, a2); assertEqual(tbl1, a2); @@ -136,8 +159,12 @@ function testAssignKeylessTableValueToVar() { {name: "Amy", id: 1234}, {name: "John", id: 4567} ]; - var ids = from var {id} in tbl1 select {id}; - var a3 = table [{"id": 1234}, {"id": 4567}]; + var ids = from var {id} in tbl1 + select {id}; + var a3 = table [ + {"id": 1234}, + {"id": 4567} + ]; assertEqual(a1, a2); assertEqual(tbl1, a2); assertEqual(tbl1, a2); @@ -149,31 +176,38 @@ function testAssignKeylessTableValueToTableType() { {name: "Amy", id: 1234}, {name: "John", id: 4567} ]; - var a2 = table key() from var {id} in tbl1 select {id}; - table a3 = a2; - var a4 = table [{"id": 1234}, {"id": 4567}]; + var a2 = table key() from var {id} in tbl1 + select {id}; + table a3 = a2; + var a4 = table [ + {"id": 1234}, + {"id": 4567} + ]; assertEqual(a3, a4); } -function testTableVlueAssignmentToAny() { - any tbl = table[]; - table> a1 = >> tbl; +function testTableValueAssignmentToAny() { + any tbl = table []; + table> a1 = >>tbl; a1.add({"any": "any"}); a1.add({"error": error("")}); any t2 = table [{a: 1}]; - table> t3 = >> t2; + table> t3 = >>t2; map m = {a: error("")}; t3.add(m); typedesc td1 = typeof a1; typedesc td2 = typeof t3; - testTableConstructorPassedAsArg(table[]); - testTableConstructorPassedAsArg(table[{a: "4"}, {g: error("")}]); + testTableConstructorPassedAsArg(table []); + testTableConstructorPassedAsArg(table [ + {a: "4"}, + {g: error("")} + ]); - assertEqual("typedesc table>", td1.toString()); - assertEqual("typedesc table>", td2.toString()); + assertEqual("typedesc table>", td1.toString()); + assertEqual("typedesc table>", td2.toString()); } function testTableConstructorPassedAsArg(any tbl) { @@ -183,6 +217,21 @@ function testTableConstructorPassedAsArg(any tbl) { panic error("Type is not table"); } +function testTableValueReturnFromFunction() { + table key(name) & readonly tab1 = getStudentTable(); + table key(name) tab2 = getStudentTable(); + _ = getStudentTable(); + + assertEqual(tab1.length(), 0); + assertEqual(tab2.length(), 0); + assertEqual(getStudentTable().length(), 0); +} + +function getStudentTable() returns readonly & table key(name) { + table key(name) & readonly studentTable = table []; + return studentTable; +} + function assertEqual(any expected, any actual) { if expected is anydata && actual is anydata && expected == actual { return;