jadams-tresys commented on a change in pull request #450:
URL: https://github.com/apache/incubator-daffodil/pull/450#discussion_r538817461



##########
File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/VariableMap1.scala
##########
@@ -232,19 +310,37 @@ class VariableMap private(vTable: Map[GlobalQName, 
MStackOf[VariableInstance]])
    */
   def readVariable(vrd: VariableRuntimeData, referringContext: ThrowsSDE, 
maybePstate: Maybe[ParseOrUnparseState]): DataValuePrimitive = {
     val varQName = vrd.globalQName
-    val stack = vTable.get(varQName)
-    if (stack.isDefined) {
-      val variable = stack.get.top
-      variable.state match {
-        case VariableRead if (variable.value.isDefined) => 
variable.value.getNonNullable
-        case VariableDefined | VariableSet if (variable.value.isDefined) => {
+    val queue = vTable.get(varQName)
+    if (queue.isDefined) {
+      val variable = queue.get.head
+      (variable.state, variable.value.isDefined, 
variable.defaultValueExpr.isDefined) match {
+        case (VariableRead, true, _) => variable.value.getNonNullable
+        case (VariableDefined | VariableSet, true, _) => {
           if (maybePstate.isDefined && maybePstate.get.isInstanceOf[PState])
             maybePstate.get.asInstanceOf[PState].markVariableRead(vrd)
 
           variable.setState(VariableRead)
           variable.value.getNonNullable
         }
-        case _ => throw new VariableHasNoValue(varQName, vrd)
+        case (VariableDefined, false, true) => {
+          variable.setState(VariableInProcess)
+          if (maybePstate.isDefined && maybePstate.get.isInstanceOf[PState]) {
+            val pstate = maybePstate.get.asInstanceOf[PState]
+            val res = 
DataValue.unsafeFromAnyRef(variable.defaultValueExpr.get.evaluate(pstate))
+
+            // Need to update the variable's value with the result of the
+            // expression
+            variable.setState(VariableRead)
+            variable.setValue(res)
+
+            res
+          } else {
+            variable.setState(VariableRead)
+            variable.value.getNonNullable

Review comment:
       So I added this else section thinking that it would get hit during 
unparsing, but after thinking it over, this will never get called during 
unparse, so I restructured this to not check to see if the given state is 
PState and removed this if/else.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to