Skip to content

IfThenElse inside Select using context not working as intended #1038

Description

@guilloulouis

Hello, I looked for a bit but was unable to find anything related to this.
I have this code snippet :

from construct import *

b1 = IfThenElse(lambda ctx: ctx._params.get('ctx') == 1, Int8ul, Int16ul)
a = Struct(
    "1" / Int8ul,
    "2" / Select(b1, Bit)
)
context = {"ctx": 1}

b = a.build({"1": 1, "2": 2}, **context)
print(len(b))  # Output: 3

I would expect to have the length of b to be 2 as my ctx provided is 1 but not it goes to the else part of the IfThenElse statement.
The behavior is correct when I remove the Select.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions