Description
Ran into this while developing schemas for a customer.
The schema for this scenario looks something like this:
<dfdl:defineVariable name="var" defaultValue="false" />
....
<dfdl:setVariable ref="var" value="true" />
...
<xs:choice dfdl:choiceDispatchKey="{ $var }">
<xs:sequence dfdl:choiceBranchKey="true">
<xs:element name="name" type="xs:string" nillable="true">
</xs:sequence>
</xs:choice>
What I believe is happening is that the nillable element is creates a mark in PState, which then gets reset as this element in the data is not nil. This causes PState to reset back to the mark, which also triggers any variables that were changed in the current scope to reset. In this case, the changes that have been tracked is the setVariable on var and the readVariable on var for the choice dispatch. So when reset gets called the variable is getting reset back to its initial default state of false.
I believe the fix for this is to simply push a new list to the changedVariablesStack whenever we create a new mark and pop the stack after resetting any changed variables, but I have not spent a lot of time on it. It fixes the issue I have and does not break any existing tests though.