From 87635fe1d400d4cb52837352cf23add360431f08 Mon Sep 17 00:00:00 2001
From: olabusayoT <50379531+olabusayoT@users.noreply.github.com>
Date: Wed, 2 Oct 2024 10:56:08 -0400
Subject: [PATCH] fixup! fixup! Generate warning when node indexed like array
- fix text and steps for Expression
- change error message for check
- update tests
- remove Subset text from error
- add nested array test
DAFFODIL-2773
---
.../daffodil/core/dpath/Expression.scala | 35 +++++--------
.../UnorderedSequences.tdml | 2 +-
.../dfdl_expressions/expressions.tdml | 10 ++--
.../dfdl_expressions/expressions3.tdml | 50 +++++++++++++++----
.../TestDFDLExpressions3.scala | 1 +
5 files changed, 59 insertions(+), 39 deletions(-)
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
index a7a4966629..354764ee30 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
@@ -773,13 +773,14 @@ case class RelativePathExpression(stepsRaw: List[StepExpression], isEvaluatedAbo
sealed abstract class StepExpression(val step: String, val pred: Option[PredicateExpression])
extends Expression {
+ final override def text: String = step + pred.map(_.text).getOrElse("")
+
def checkIfNodeIndexedLikeArray(): Unit = {
- if (pred.isDefined) {
- SDE(
- "Expression contains indexing on a node element: %s.",
- this.wholeExpressionText
- )
- }
+ schemaDefinitionWhen(
+ pred.isDefined,
+ "Indexing is only allowed on arrays. Offending path step: '%s'.",
+ this.text
+ )
}
def relPathErr() = {
@@ -1028,7 +1029,6 @@ sealed abstract class SelfStepExpression(s: String, predArg: Option[PredicateExp
checkIfNodeIndexedLikeArray()
new CompiledDPath(SelfMove)
}
- override def text = "." + predArg.map(_.text).getOrElse("")
protected def stepElementDefs: Seq[DPathElementCompileInfo] = {
if (this.isFirstStep) {
@@ -1046,7 +1046,7 @@ sealed abstract class SelfStepExpression(s: String, predArg: Option[PredicateExp
}
}
-case class Self(predArg: Option[PredicateExpression]) extends SelfStepExpression(null, predArg)
+case class Self(predArg: Option[PredicateExpression]) extends SelfStepExpression(".", predArg)
/**
* Different from Self in that it verifies the qName (s) is
@@ -1065,8 +1065,6 @@ case class Self2(s: String, predArg: Option[PredicateExpression])
sealed abstract class UpStepExpression(s: String, predArg: Option[PredicateExpression])
extends StepExpression(s, predArg) {
- override def text = ".." + predArg.map(_.text).getOrElse("")
-
final override lazy val compiledDPath = {
val areAllArrays = isLastStep && stepElements.forall {
_.isArray
@@ -1074,7 +1072,7 @@ sealed abstract class UpStepExpression(s: String, predArg: Option[PredicateExpre
if (areAllArrays) {
new CompiledDPath(UpMoveArray)
} else {
- checkIfNodeIndexedLikeArray
+ checkIfNodeIndexedLikeArray()
new CompiledDPath(UpMove)
}
}
@@ -1102,7 +1100,7 @@ sealed abstract class UpStepExpression(s: String, predArg: Option[PredicateExpre
override lazy val inherentType: NodeInfo.Kind = NodeInfo.Complex
}
-case class Up(predArg: Option[PredicateExpression]) extends UpStepExpression(null, predArg)
+case class Up(predArg: Option[PredicateExpression]) extends UpStepExpression("..", predArg)
/**
* Different from Up in that it verifies the qName (s) is the
@@ -1111,8 +1109,6 @@ case class Up(predArg: Option[PredicateExpression]) extends UpStepExpression(nul
case class Up2(s: String, predArg: Option[PredicateExpression])
extends UpStepExpression(s, predArg) {
- override def text = ".."
-
override protected def stepElementDefs: Seq[DPathElementCompileInfo] = {
val cis = super.stepElementDefs
verifyQNames(cis)
@@ -1156,22 +1152,15 @@ case class NamedStep(s: String, predArg: Option[PredicateExpression])
new DownArray(nqn)
}
} else {
- // a[exp] is only supported on arrays , because Daffodil no longer treats
+ // a[exp] is only supported on arrays, because Daffodil no longer treats
// optional elements as arrays
- if (pred.isDefined)
- subsetError(
- "Indexing is only allowed on arrays. Offending path step: '%s%s'.",
- step,
- pred.get.text
- )
+ checkIfNodeIndexedLikeArray()
// the downward element step must be the same for all the possible elements, so
// we can pick the first one arbitrarily.
new DownElement(nqn)
}
}
- override def text = step
-
/*
* The ERDs of the elements that correspond to this path step
* (or SDE trying to find them.)
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/UnorderedSequences.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/UnorderedSequences.tdml
index e97d67ff58..0bd102aded 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/UnorderedSequences.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section14/unordered_sequences/UnorderedSequences.tdml
@@ -627,7 +627,7 @@
Schema Definition Error
- Subset: Indexing is only allowed on arrays
+ Indexing is only allowed on arrays
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
index a20b94a17f..e96d00d0f3 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
@@ -4427,7 +4427,7 @@ blastoff
Test Name: predicate_05
Schema: predicates
Root: e5
- Purpose: This test demonstrates that subset indexing is only allowed on arrays.
+ Purpose: This test demonstrates that indexing is only allowed on arrays.
-->
2,one,two,three
Schema Definition Error
- Subset: Indexing is only allowed on arrays.
+ Indexing is only allowed on arrays.
@@ -4444,7 +4444,7 @@ blastoff
Test Name: predicate_06
Schema: predicates
Root: e6
- Purpose: This test demonstrates that subset indexing is not allowed on optionals
+ Purpose: This test demonstrates that indexing is not allowed on optionals
-->
2,one
Schema Definition Error
- Subset: Indexing is only allowed on arrays.
+ Indexing is only allowed on arrays.
@@ -7297,7 +7297,7 @@ blastoff
1,2,3
Schema Definition Error
- Subset: Indexing is only allowed on arrays
+ Indexing is only allowed on arrays
ex:a
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions3.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions3.tdml
index ce8b0663f9..d3be2bb525 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions3.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions3.tdml
@@ -536,6 +536,26 @@
+
+
+
+
+
+
+
+
+
+
+ { fn:exists(..[1]) }
+
+
+
+
+
+
+
+
+
@@ -543,9 +563,9 @@
1|2|3
Schema Definition Error
- Expression contains
- indexing
- node element
+ Indexing
+ only allowed
+ arrays
.[1]
@@ -554,9 +574,9 @@
1
Schema Definition Error
- Expression contains
- indexing
- node element
+ Indexing
+ only allowed
+ arrays
.[1]
@@ -565,7 +585,6 @@
1
Schema Definition Error
- Subset
Indexing
only allowed
arrays
@@ -577,9 +596,20 @@
1
Schema Definition Error
- Expression contains
- indexing
- node element
+ Indexing
+ only allowed
+ arrays
+ ..[1]
+
+
+
+
+ 123|456|789
+
+ Schema Definition Error
+ Indexing
+ only allowed
+ arrays
..[1]
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions3.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions3.scala
index 8f2bdcebc3..fa11db7956 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions3.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions3.scala
@@ -50,6 +50,7 @@ class TestDFDLExpressions3 {
@Test def test_array_self_expr2(): Unit = { runner.runOneTest("test_array_self_expr2") }
@Test def test_array_path_expr1(): Unit = { runner.runOneTest("test_array_path_expr1") }
@Test def test_array_path_expr2(): Unit = { runner.runOneTest("test_array_path_expr2") }
+ @Test def test_array_path_expr3(): Unit = { runner.runOneTest("test_array_path_expr3") }
@Test def test_setVariable_neg_01(): Unit = { runner.runOneTest("setVariable_neg_01") }