Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/LS25000557/MOVEA from DS to S #703

Merged
merged 15 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,15 +1034,27 @@ 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
fun executeERROR53CallBackTest() {
executePgmCallBackTest("ERROR53", SourceReferenceType.Copy, "QILEGEN,£PDS", listOf(130))
}

@Test
fun executeERROR53SourceLineTest() {
executeSourceLineTest("ERROR53")
}

@Test
fun bypassSyntaxErrorTest() {
val configuration = Configuration().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
15 changes: 15 additions & 0 deletions rpgJavaInterpreter-core/src/test/resources/ERROR51.rpgle
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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