diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/move_a.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/move_a.kt index ac19401b3..0c4fd45b9 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/move_a.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/move_a.kt @@ -56,6 +56,10 @@ private fun moveaNumber( interpreterCore: InterpreterCore, value: Expression ): ConcreteArrayValue { + if (value is DataRefExpr && value.variable.referred?.type is DataStructureType) { + throw IllegalStateException("You cannot move a DS into a numeric array: ${value.render()} (${value.position})") + } + val targetArray = interpreterCore.get(target.variable.referred!!).asArray() val newValue = interpreterCore.toArray(value, targetArray.elementType) val arrayValue = createArrayValue(baseType(target.type()), target.type().numberOfElements()) { diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/values.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/values.kt index 34a155c04..f07233859 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/values.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/values.kt @@ -1342,6 +1342,10 @@ data class DataStructValue(@Contextual val value: DataStructValueBuilder, privat result = 31 * result + unlimitedStringField.hashCode() return result } + + override fun takeFirst(n: Int): Value { + return getSubstring(0, if (n <= len) n else len) + } } fun Int.asValue() = IntValue(this.toLong()) diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt index 9b6d633c3..289341b1a 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/interpreter/JarikoCallbackTest.kt @@ -1034,8 +1034,15 @@ class JarikoCallbackTest : AbstractTest() { } @Test - fun executeERROR53SourceLineTest() { - executeSourceLineTest("ERROR53") + fun executeERROR51CallBackTest() { + executePgmCallBackTest("ERROR51", SourceReferenceType.Program, "ERROR51", mapOf( + 13 to "You cannot move a DS into a numeric array: SCAATTDS (Position(start=Line 13, Column 35, end=Line 13, Column 43))" + )) + } + + @Test + fun executeERROR51SourceLineTest() { + executeSourceLineTest("ERROR51") } @Test @@ -1043,6 +1050,11 @@ class JarikoCallbackTest : AbstractTest() { executePgmCallBackTest("ERROR53", SourceReferenceType.Copy, "QILEGEN,£PDS", listOf(130)) } + @Test + fun executeERROR53SourceLineTest() { + executeSourceLineTest("ERROR53") + } + @Test fun bypassSyntaxErrorTest() { val configuration = Configuration().apply { diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt index 966557903..7e2a2213f 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt @@ -928,4 +928,34 @@ open class MULANGT10BaseCodopTest : MULANGTTest() { val expected = listOf("1", "0") assertEquals(expected, "smeup/MUDRNRAPU00280".outputOf(configuration = smeupConfig)) } + + /** + * MOVEA from DS to S defined as array. + * @see #LS25000557 + */ + @Test + fun executeMUDRNRAPU00195() { + val expected = listOf("0123456789", "", "0123456789", "0123456789") + assertEquals(expected, "smeup/MUDRNRAPU00195".outputOf()) + } + + /** + * MOVEA from DS to S defined as array, with size lower than DS. + * @see #LS25000557 + */ + @Test + fun executeMUDRNRAPU00196() { + val expected = listOf("0123456789", "", "0123456789", "01234567") + assertEquals(expected, "smeup/MUDRNRAPU00196".outputOf()) + } + + /** + * MOVEA from DS to S defined as array, with size greater than DS. + * @see #LS25000557 + */ + @Test + fun executeMUDRNRAPU00197() { + val expected = listOf("0123456789", "", "0123456789", "0123456789") + assertEquals(expected, "smeup/MUDRNRAPU00197".outputOf()) + } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/ERROR51.rpgle b/rpgJavaInterpreter-core/src/test/resources/ERROR51.rpgle new file mode 100644 index 000000000..99d643e63 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/ERROR51.rpgle @@ -0,0 +1,15 @@ + V* ============================================================== + D* 05/02/25 + D* Purpose: Must fire the following errors during execution of + D* `C MOVEA SCAATTDS SCAATT`: + D* line 13 - "You cannot move a DS into a numeric array" + D* because isn't possible to assign DS to a Standalone defined + D* as number + V* ============================================================== + D SCAATTDS DS 10 + D SCAATT S 1 0 DIM(10) + + C EVAL SCAATTDS='0123456789' + C MOVEA SCAATTDS SCAATT + + C SETON LR \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00195.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00195.rpgle new file mode 100644 index 000000000..5e64a88a6 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00195.rpgle @@ -0,0 +1,35 @@ + V* ============================================================== + V* 05/02/2025 APU001 Creation + V* ============================================================== + O * PROGRAM GOAL + O * MOVEA from DS to S defined as array. + V* ============================================================== + O * JARIKO ANOMALY + O * An operation is not implemented: takeFirst not yet implemented + O * for DataStructValue. + V* ============================================================== + D SCAATTDS DS 10 + D SCAATTSTR S 10 + D SCAATT S 1 DIM(10) + D I S 2 0 + + C EVAL SCAATTDS='0123456789' + C EXSR SHOW + + C MOVEA SCAATTDS SCAATT #Issue executing MoveAStmt at line 4. An operation is not implemented: takeFirst not yet implemented for DataStructValue + C EXSR SHOW + + C SETON LR + + + + C SHOW BEGSR + + C SCAATTDS DSPLY + C CLEAR SCAATTSTR + C FOR I = 1 TO 10 + C EVAL SCAATTSTR=%TRIM(SCAATTSTR)+ + C %CHAR(SCAATT(I)) + C ENDFOR + C SCAATTSTR DSPLY + C ENDSR \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00196.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00196.rpgle new file mode 100644 index 000000000..16ebf1698 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00196.rpgle @@ -0,0 +1,31 @@ + V* ============================================================== + V* 06/02/2025 APU001 Creation + V* ============================================================== + O * PROGRAM GOAL + O * MOVEA from DS to S defined as array, with size lower than DS. + V* ============================================================== + D SCAATTDS DS 10 + D SCAATTSTR S 8 + D SCAATT S 1 DIM(8) + D I S 1 0 + + C EVAL SCAATTDS='0123456789' + C EXSR SHOW + + C MOVEA SCAATTDS SCAATT + C EXSR SHOW + + C SETON LR + + + + C SHOW BEGSR + + C SCAATTDS DSPLY + C CLEAR SCAATTSTR + C FOR I = 1 TO 8 + C EVAL SCAATTSTR=%TRIM(SCAATTSTR)+ + C %CHAR(SCAATT(I)) + C ENDFOR + C SCAATTSTR DSPLY + C ENDSR \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00197.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00197.rpgle new file mode 100644 index 000000000..cc234fe26 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00197.rpgle @@ -0,0 +1,32 @@ + V* ============================================================== + V* 06/02/2025 APU001 Creation + V* ============================================================== + O * PROGRAM GOAL + O * MOVEA from DS to S defined as array, with size greater + O * than DS. + V* ============================================================== + D SCAATTDS DS 10 + D SCAATTSTR S 12 + D SCAATT S 1 DIM(12) + D I S 2 0 + + C EVAL SCAATTDS='0123456789' + C EXSR SHOW + + C MOVEA SCAATTDS SCAATT + C EXSR SHOW + + C SETON LR + + + + C SHOW BEGSR + + C SCAATTDS DSPLY + C CLEAR SCAATTSTR + C FOR I = 1 TO 12 + C EVAL SCAATTSTR=%TRIM(SCAATTSTR)+ + C %CHAR(SCAATT(I)) + C ENDFOR + C SCAATTSTR DSPLY + C ENDSR \ No newline at end of file