Fix decoding of single-element payload members - #51
Open
glopesdev wants to merge 1 commit into
Open
Conversation
A payload member declaring a length now emits an array whatever number the length holds, so a member declaring length 1 emits a one-element array rather than a scalar. The converter context keeps the declared length as None when the schema declares none, instead of collapsing an absent length into 1, which made the two indistinguishable. Registers already behaved this way; only members did not. The test device schema and the generated module it is compared against are resynced from harp-tech/generators.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This affects modules built from a
device.ymlat runtime, throughharp.device.schema. Device packages generated ahead of time by harp-tech/generators take a different path and are unaffected.A payload member that declares a length now emits an array whatever number the length holds, so a member declaring
length: 1emits a one-element array. A member declaring no length still emits a scalar.ConverterContext.lengthkeeps the declared value asNonewhen the schema declares none, rather than collapsing an absent length into 1 and then treating only> 1as an array. That collapse made an absent length and a declared 1 indistinguishable, which is the same defect #44 fixed for registers; it corrected_build_registerand left the member path as it was.spangains an explicit floor of one element, which is now the only place that default lives.How it surfaced
harp-tech/generatorsfixed the matching rule in its own target and added three registers to the shared test schema to cover it: an array register, an array register of one element, and a payload whose members declare no length,length: 1andlength: 2. Resyncing that schema and the generated module here is what exposed the divergence, sinceMixedMemberLengthfails against the old emitter and passes against this one.No published device schema declares a length on a payload member, so nothing in the ecosystem decodes incorrectly today.
Notes for review
tests/assets/core.ymlwas already identical and is untouched.tests/device/converters.pytakes only theConverter[np.int32]retype, matching the type the schema promises for aninterfaceTypeofint. The rest of that file stays as it is, since it deliberately omits the upstream module docstring and follows the formatting here.