diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt index e646472ec..2bf572a32 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt @@ -243,7 +243,6 @@ fun coerce(value: Value, type: Type): Value { } else { return DecimalValue(value.value.setScale(type.decimalDigits)) } - return value } else -> TODO("Converting DecimalValue to $type") } diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt index 909135787..f3f9d008a 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt @@ -872,26 +872,9 @@ private fun RpgParser.Parm_fixedContext.toFieldInfo(conf: ToAstConfiguration = T } var initializationValue: Expression? = null + val arraySizeDeclared = this.arraySizeDeclared(conf) val hasInitValue = this.keyword().find { it.keyword_inz() != null } - if (hasInitValue != null) { - if (hasInitValue.keyword_inz().simpleExpression() != null) { - initializationValue = hasInitValue.keyword_inz().simpleExpression()?.toAst(conf) as Expression - } else { - // TODO handle initializations for any other variables type (es. 'Z' for timestamp) - initializationValue = if (null != this.toTypeInfo().decimalPositions) { - RealLiteral(BigDecimal.ZERO, position = toPosition()) - } else { - StringLiteral("", position = toPosition()) - } - } - } else { - this.toDSFieldInitKeyword(conf = conf)?.apply { - initializationValue = this.toAst() - } - } - // compileTimeInterpreter.evaluate(this.rContext(), dim!!).asInt().value.toInt(), - val arraySizeDeclared = this.arraySizeDeclared(conf) val varName = like?.variable?.name ?: this.name val explicitElementType: Type? = this.calculateExplicitElementType(arraySizeDeclared, conf) ?: knownDataDefinitions.firstOrNull { it.name.equals(varName, ignoreCase = true) }?.type @@ -903,6 +886,23 @@ private fun RpgParser.Parm_fixedContext.toFieldInfo(conf: ToAstConfiguration = T ).evaluateTypeOf(this.rContext(), it, conf) } + if (hasInitValue != null) { + initializationValue = if (hasInitValue.keyword_inz().simpleExpression() != null) { + hasInitValue.keyword_inz().simpleExpression()?.toAst(conf) as Expression + } else { + // TODO handle initializations for any other variables type (es. 'Z' for timestamp) + when { + arraySizeDeclared != null -> null + this.toTypeInfo().decimalPositions != null -> RealLiteral(BigDecimal.ZERO, position = toPosition()) + else -> StringLiteral("", position = toPosition()) + } + } + } else { + this.toDSFieldInitKeyword(conf = conf)?.apply { + initializationValue = this.toAst() + } + } + return FieldInfo(this.name, overlayInfo = overlayInfo, explicitStartOffset = this.explicitStartOffset(), explicitEndOffset = if (explicitStartOffset() != null) this.explicitEndOffset() else null, diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt index 3f049959c..d080d0a65 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt @@ -572,4 +572,14 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() { val expected = listOf("ok") assertEquals(expected, "smeup/MUDRNRAPU00247".outputOf(configuration = smeupConfig)) } + + /** + * Array declaration inside a DS with an empty INZ keyword + * @see #LS24003783 + */ + @Test + fun executeMUDRNRAPU00249() { + val expected = listOf(List(99) { "0" }.toString()) + assertEquals(expected, "smeup/MUDRNRAPU00249".outputOf(configuration = smeupConfig)) + } } diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle new file mode 100644 index 000000000..7733f128f --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle @@ -0,0 +1,7 @@ + * Declaring an array field (£6I) in a data structure with an empty INZ keyword. + * Should not be assigned to a numeric + D £C6MIM DS + D £6I 20P 6 DIM(99) INZ Importi + + * Test output + C £6I DSPLY