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

transform: flatten mangler: handle nil subfields #89

Merged
merged 1 commit into from
May 16, 2024

Conversation

dfinkel
Copy link
Contributor

@dfinkel dfinkel commented May 16, 2024

Fix the FlattenMangler so it doesn't populate intermediate struct-fields
of pointer-type. Since pointerification pretty much always converts
these fields to pointers, this is the common case.

There was a bit of missing accounting, so with two structs:

type A struct {
	Field1 *int
	Field2 *string
}
struct B struct{
	Field3 *A
}

B.Field3 was always populated with the zero-value, even if both
B.Field3_Field1 and B.Field3_Field2 are nil.

This change fixes the case where all underlying fields are nil, and
prevents those intermediate fields from getting set to non-nil values.

Fix the FlattenMangler so it doesn't populate intermediate struct-fields
of pointer-type. Since pointerification pretty much always converts
these fields to pointers, this is the common case.

There was a bit of missing accounting, so with two structs:
```go
type A struct {
	Field1 *int
	Field2 *string
}
struct B struct{
	Field3 *A
}
```

`B.Field3` was always populated with the zero-value, even if both
`B.Field3_Field1` and `B.Field3_Field2` are `nil`.

This change fixes the case where all underlying fields are `nil`, and
prevents those intermediate fields from getting set to non-`nil` values.
@dfinkel dfinkel merged commit 473d614 into master May 16, 2024
6 checks passed
@dfinkel dfinkel deleted the flatten_mangler_nil_intermediate_types branch May 16, 2024 22:10
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.

2 participants