Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bindnode): tuple struct iterator should handle absent fields properly #368

Merged
merged 1 commit into from
Feb 23, 2022

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Feb 23, 2022

Fixes: #367

@@ -320,7 +322,7 @@ _skipAbsent:
if err != nil {
return 0, nil, err
}
if value.IsAbsent() {
if w.nextIndex > w.reprEnd {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to be in a situation where value.IsAbsent() and we're not at the end amongst trailing absents? e.g. [absent,present,present,absent,absent]? Is there a use of this iterator where that can happen, perhaps by constructing this from the typed form and then list iterating on the repr form?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absents can only be at the end, as per the undocumented spec :) See

// Optional fields for tuple representation are only allowed at the end, and contiguously.
.

Arguably this needs to be properly documented in the specs, which is why I'll raise an issue elsewhere. But in short: we should support trailingn optionals in bindnode, to at least match codegen in terms of features.

@rvagg
Copy link
Member Author

rvagg commented Feb 23, 2022

btw, I could go either way on the tuple optionals, I've always thought that it was reasonable to allow trailing optionals but it does complicate matters somewhat for marginal gain and increased ambiguity. Maybe we should rip that support out (for now, or for good?)

@@ -932,6 +930,7 @@ func (w *_listStructAssemblerRepr) AssembleValue() datamodel.NodeAssembler {
}}
}
field := fields[w.nextIndex]
w.doneFields[w.nextIndex] = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, nice catch.

node/bindnode/repr.go Show resolved Hide resolved
@@ -320,7 +322,7 @@ _skipAbsent:
if err != nil {
return 0, nil, err
}
if value.IsAbsent() {
if w.nextIndex > w.reprEnd {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absents can only be at the end, as per the undocumented spec :) See

// Optional fields for tuple representation are only allowed at the end, and contiguously.
.

Arguably this needs to be properly documented in the specs, which is why I'll raise an issue elsewhere. But in short: we should support trailingn optionals in bindnode, to at least match codegen in terms of features.

@mvdan
Copy link
Contributor

mvdan commented Feb 23, 2022

TL;DR fine to merge as is, looks great!

@rvagg rvagg merged commit 70450e9 into master Feb 23, 2022
@rvagg rvagg deleted the rvagg/bindnode-tuple-iterator branch February 23, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AssignNode from a representation form of a TypedNode including a tuple panics with default values
2 participants