Skip to content

Commit

Permalink
Merge pull request #695 from smeup/bugfix/LS25000333/ds-like-to-string
Browse files Browse the repository at this point in the history
Bugfix/ls25000333/ds like to string
  • Loading branch information
lanarimarco authored Jan 23, 2025
2 parents bd1e961 + b6abb6b commit 289d47a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ internal fun RpgParser.DspecContext.toAst(
NumberType(elementSize!! - decimalPositions, decimalPositions)
} else {
if (like != null) {
compileTimeInterpreter.evaluateTypeOf(this.rContext(), like!!, conf, procedureName)
val baseType = compileTimeInterpreter.evaluateTypeOf(this.rContext(), like!!, conf, procedureName)

// When LIKE is used on a DS we must declare a string with size == to the DS size
if (baseType is DataStructureType) {
StringType.createInstance(elementSize!!, varying)
} else baseType
} else {
StringType.createInstance(elementSize!!, varying)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.smeup.rpgparser.smeup

import com.smeup.rpgparser.db.utilities.DBServer
import com.smeup.rpgparser.interpreter.DataDefinition
import com.smeup.rpgparser.interpreter.DataStructureType
import com.smeup.rpgparser.interpreter.StringType
import com.smeup.rpgparser.smeup.dbmock.MULANGTLDbMock
import org.junit.Test
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.assertEquals
import kotlin.test.*

open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
@BeforeTest
Expand Down Expand Up @@ -427,7 +428,7 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
*/
@Test
fun executeMUDRNRAPU00227() {
val expected = listOf("9991\uFFFF\uFFFF99999")
val expected = listOf("\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF")
assertEquals(expected, "smeup/MUDRNRAPU00227".outputOf(configuration = smeupConfig))
}

Expand Down Expand Up @@ -867,4 +868,23 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
val expected = listOf("IBMI", "", "IBMI")
assertEquals(expected, "smeup/MUDRNRAPU00190".outputOf(configuration = smeupConfig))
}

/**
* Definitions with LIKE referencing a DS must be defined as strings with the same size as the DS
* @see #LS25000333
*/
@Test
fun executeMUDRNRAPU00281() {
var mlDataDefinition: DataDefinition? = null
var ds0002DataDefinition: DataDefinition? = null

assertASTCanBeProduced("smeup/MUDRNRAPU00281", afterAstCreation = {
mlDataDefinition = it.getDataDefinition("ML")
ds0002DataDefinition = it.getDataDefinition("DS0002")
})

assertIs<DataStructureType>(mlDataDefinition?.type)
assertIs<StringType>(ds0002DataDefinition?.type)
assertEquals(mlDataDefinition?.elementSize(), ds0002DataDefinition?.elementSize())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{"name": "MULANGTL",
"tableName": "MULANGTF",
"recordFormat": "MULANGR",
"fields": [
{ "fieldName": "MLSYST",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":20, "varying":false}}
, { "fieldName": "MLLIBR",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLFILE",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLTIPO",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLPROG",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLPSEZ",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLPPAS",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLPDES",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":256, "varying":false}}
, { "fieldName": "MLSQIN",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLSQFI",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLAAAT",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":1024, "varying":false}}
, { "fieldName": "MLAAVA",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":1024, "varying":false}}
, { "fieldName": "MLNNAT",
"type":{"type":"com.smeup.rpgparser.interpreter.NumberType","entireDigits":21, "decimalDigits":9, "rpgType":"P"}}
, { "fieldName": "MLNNVA",
"type":{"type":"com.smeup.rpgparser.interpreter.NumberType","entireDigits":21, "decimalDigits":9, "rpgType":"P"}}
, { "fieldName": "MLINDI",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":99, "varying":false}}
, { "fieldName": "MLTEES",
"type":{"type":"com.smeup.rpgparser.interpreter.NumberType","entireDigits":8, "decimalDigits":0, "rpgType":"P"}}
, { "fieldName": "MLUSES",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLDTES",
"type":{"type":"com.smeup.rpgparser.interpreter.NumberType","entireDigits":8, "decimalDigits":0, "rpgType":"S"}}
, { "fieldName": "MLORES",
"type":{"type":"com.smeup.rpgparser.interpreter.NumberType","entireDigits":6, "decimalDigits":0, "rpgType":"S"}}
, { "fieldName": "MLASLA",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":10, "varying":false}}
, { "fieldName": "MLASNR",
"type":{"type":"com.smeup.rpgparser.interpreter.NumberType","entireDigits":6, "decimalDigits":0, "rpgType":"P"}}
, { "fieldName": "MLLIBE",
"type":{"type":"com.smeup.rpgparser.interpreter.StringType","length":30000, "varying":true}}
], "accessFields": [ "MLSYST", "MLTIPO", "MLPROG", "MLPSEZ", "MLPPAS"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
V* ==============================================================
V* 21/01/2025 APU002 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Definitions with LIKE 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* ==============================================================
FMULANGTL IF E K DISK
D ML E DS EXTNAME(MULANGTL) INZ
D DS0002 S LIKE(ML)

0 comments on commit 289d47a

Please sign in to comment.