diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt index ec15e17d6..82135613f 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt @@ -1306,6 +1306,21 @@ data class DefineStmt( val containingCU = this.ancestor(CompilationUnit::class.java) ?: return emptyList() + val indicatorPattern = Regex("\\*IN\\d\\d") + val normalizedOriginalName = originalName.trim().uppercase() + val isIndicator = normalizedOriginalName.matches(indicatorPattern) + if (isIndicator) { + val indicatorKey = normalizedOriginalName.removePrefix("*IN").toIndicatorKey() + val setStatements = containingCU.main.stmts.explode(true).filterIsInstance() + val definedIndicators = setStatements.map { it.indicators }.flatten().filterIsInstance() + val isIndicatorDefined = definedIndicators.any { it.index == indicatorKey } + + if (!isIndicatorDefined) throw Error("Data reference $originalName not resolved") + + val newDefinition = InStatementDataDefinition(newVarName, BooleanType, position) + return listOf(newDefinition) + } + // Search standalone 'D spec' or InStatement definition val originalDataDefinition = containingCU.dataDefinitions.find { it.name == originalName } ?: containingCU.getInStatementDataDefinitions().find { it.name == originalName } 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 c5d9c999b..f4a20e2ef 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 @@ -1009,6 +1009,18 @@ class JarikoCallbackTest : AbstractTest() { executeSourceLineTest("ERROR48") } + @Test + fun executeERROR49CallBackTest() { + executePgmCallBackTest("ERROR49", SourceReferenceType.Program, "ERROR49", mapOf( + 6 to "Data reference *IN10 not resolved" + )) + } + + @Test + fun executeERROR49SourceLineTest() { + executeSourceLineTest("ERROR49") + } + @Test fun bypassSyntaxErrorTest() { val configuration = Configuration().apply { 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 46deca8df..985ca9309 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 @@ -794,6 +794,16 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() { assertEquals(expected, "smeup/MUDRNRAPU00270".outputOf(configuration = smeupConfig)) } + /** + * DEFINE with indicator as original name + * @see #LS24005143 + */ + @Test + fun executeMUDRNRAPU00273() { + val expected = listOf("1", "0") + assertEquals(expected, "smeup/MUDRNRAPU00273".outputOf(configuration = smeupConfig)) + } + /** * Truncation of number by using Z-ADD. The source is greater than destination. * Source and destination are integer. diff --git a/rpgJavaInterpreter-core/src/test/resources/ERROR49.rpgle b/rpgJavaInterpreter-core/src/test/resources/ERROR49.rpgle new file mode 100644 index 000000000..dc7da975e --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/ERROR49.rpgle @@ -0,0 +1,6 @@ + V* ============================================================== + D* 02/12/24 + D* Purpose: Must fire the following errors during execution of + D* line 6 - Data reference *IN10 not resolved + V* ============================================================== + C *LIKE DEFINE *IN10 XIN10 diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00273.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00273.rpgle new file mode 100644 index 000000000..e85f3507c --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00273.rpgle @@ -0,0 +1,15 @@ + V* ============================================================== + V* 28/11/2024 APU002 Creation + V* ============================================================== + O * PROGRAM GOAL + O * DEFINE on an indicator + V* ============================================================== + O * JARIKO ANOMALY + O * Before the fix, jariko throw a DataReference error + V* ============================================================== + C SETON 10 + C EVAL XIN10=*ON + C XIN10 DSPLY + C EVAL XIN10=*OFF + C XIN10 DSPLY + C *LIKE DEFINE *IN10 XIN10