Skip to content

Commit

Permalink
Merge pull request #697 from smeup/bugfix/LS25000333/ds-like-define-t…
Browse files Browse the repository at this point in the history
…o-string

Bugfix/ls25000333/ds like define to string
  • Loading branch information
lanarimarco authored Jan 24, 2025
2 parents 289d47a + f82e4e2 commit 8076bc5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,10 @@ data class DefineStmt(
}

if (originalDataDefinition != null) {
return listOf(InStatementDataDefinition(newVarName, originalDataDefinition.type, position))
val newType = if (originalDataDefinition.type is DataStructureType) {
StringType.createInstance(originalDataDefinition.elementSize())
} else originalDataDefinition.type
return listOf(InStatementDataDefinition(newVarName, newType, position))
} else {
if (!this.enterInStack()) {
// This check is necessary to avoid infinite recursion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.smeup.rpgparser.smeup

import com.smeup.rpgparser.db.utilities.DBServer
import com.smeup.rpgparser.interpreter.AbstractDataDefinition
import com.smeup.rpgparser.interpreter.DataDefinition
import com.smeup.rpgparser.interpreter.DataStructureType
import com.smeup.rpgparser.interpreter.StringType
import com.smeup.rpgparser.parsing.parsetreetoast.resolveAndValidate
import com.smeup.rpgparser.smeup.dbmock.MULANGTLDbMock
import org.junit.Test
import kotlin.test.*
Expand Down Expand Up @@ -887,4 +889,24 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
assertIs<StringType>(ds0002DataDefinition?.type)
assertEquals(mlDataDefinition?.elementSize(), ds0002DataDefinition?.elementSize())
}

/**
* Definitions with *LIKE DEFINE referencing a DS must be defined as strings with the same size as the DS
* @see #LS25000333
*/
@Test
fun executeMUDRNRAPU00282() {
var aDefinition: AbstractDataDefinition? = null
var bDefinition: AbstractDataDefinition? = null

assertASTCanBeProduced("smeup/MUDRNRAPU00282", afterAstCreation = {
it.resolveAndValidate() // Needed to solve InStatementDataDefinitions
aDefinition = it.allDataDefinitions.firstOrNull { def -> def.name.equals("\$A", ignoreCase = true) }
bDefinition = it.allDataDefinitions.firstOrNull { def -> def.name.equals("\$B", ignoreCase = true) }
})

assertIs<DataStructureType>(aDefinition?.type)
assertIs<StringType>(bDefinition?.type)
assertEquals(aDefinition?.elementSize(), bDefinition?.elementSize())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
V* ==============================================================
V* 24/01/2025 APU002 Creation
V* ==============================================================
O * PROGRAM GOAL
O * *LIKE DEFINE referencing a DS must be defined as
0 * strings with the same size as the DS
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, they were defined as DS themselves
V* ==============================================================
D $A DS 512
C *LIKE DEFINE $A $B

0 comments on commit 8076bc5

Please sign in to comment.