You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2023/02/07 22:22:47 UTC

[daffodil] branch main updated: Pass through dfdlx:trace argument unchanged

This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 45a73676a Pass through dfdlx:trace argument unchanged
45a73676a is described below

commit 45a73676a53b88f177f4c1855232e4f8c4e1a97c
Author: Mike McGann <mm...@owlcyberdefense.com>
AuthorDate: Tue Feb 7 16:02:25 2023 -0500

    Pass through dfdlx:trace argument unchanged
    
    An assertion with the test expression {dfdlx:trace(42, 'answer')}
    was converting the first argument to a boolean and then also attemping to
    convert it again when used as a return value. This update passes through
    the argument without converting its type to boolean.
    
    DAFFODIL-2628
---
 .../apache/daffodil/core/dpath/Expression.scala    |  6 +++---
 .../section23/dfdl_expressions/expressions2.tdml   | 25 ++++++++++++++++++++++
 .../dfdl_expressions/TestDFDLExpressions.scala     |  3 +++
 3 files changed, 31 insertions(+), 3 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 334130008..15fc9b821 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
@@ -2482,11 +2482,11 @@ case class DFDLXTraceExpr(nameAsParsed: String, fnQName: RefQName, args: List[Ex
   }
 
   override lazy val inherentType: NodeInfo.Kind = realArg.inherentType
-  override def targetTypeForSubexpression(subExp: Expression): NodeInfo.Kind = targetType
 
-  override lazy val compiledDPath = {
+  override def targetTypeForSubexpression(subExp: Expression): NodeInfo.Kind = inherentType
+
+  override lazy val compiledDPath =
     new CompiledDPath(DFDLXTrace(realArg.compiledDPath, msgText) +: conversions)
-  }
 }
 
 case class DAFErrorExpr(nameAsParsed: String, fnQName: RefQName, args: List[Expression])
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions2.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions2.tdml
index 6aea266dd..22c9db224 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions2.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions2.tdml
@@ -261,6 +261,31 @@
 
   </tdml:parserTestCase>
 
+  <tdml:defineSchema name="traceReturnType">
+    <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+    <dfdl:format ref="ex:GeneralFormat" />
+
+    <xs:element name="e1" dfdl:lengthKind="explicit"
+                dfdl:length="2" type="xs:string">
+      <xs:annotation>
+        <xs:appinfo source="http://www.ogf.org/dfdl/">
+          <dfdl:assert test="{dfdlx:trace(42, 'answer')}"/>
+        </xs:appinfo>
+      </xs:annotation>
+    </xs:element>
+  </tdml:defineSchema>
+
+  <tdml:parserTestCase name="traceReturnType"
+                       root="e1" model="traceReturnType"
+                       description="argument to trace passes back unchanged and can be used in assert">
+    <tdml:document>42</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <ex:e1>42</ex:e1>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
   <tdml:parserTestCase name="unused_path_no_context_01" model="expressions_unused_path_no_context.dfdl.xsd"
     description="Section 06 - DFDL Expressions - DFDL-6-083R" root="e1">
     <tdml:document>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions.scala
index 08ed03873..7c8e62b3c 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section23/dfdl_expressions/TestDFDLExpressions.scala
@@ -1032,6 +1032,9 @@ class TestDFDLExpressions {
   // DFDL-1804
   @Test def test_traceComplex(): Unit = { runner7.runOneTest("traceComplex") }
 
+  // DFDL-2628
+  @Test def test_traceReturnType(): Unit = { runner7.runOneTest("traceReturnType") }
+
   //DFDL-1076
   @Test def test_nilled_01(): Unit = { runner2.runOneTest("nilled_01") }