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 basic type conversions from pointer to non-pointer #43

Merged
merged 3 commits into from
Oct 27, 2023

Conversation

rboyer
Copy link
Member

@rboyer rboyer commented Oct 27, 2023

Conversions from things like bool <-> *bool or uint32 <-> *uint32 would panic if the RHS was nil as it would just generate:

x = *y

This fixes it so that it does the following in that scenario:

if y != nil {
  x = *y
} else {
  var z <original_type>
  x = z
}

@rboyer rboyer self-assigned this Oct 27, 2023
@rboyer rboyer requested a review from a team as a code owner October 27, 2023 17:22
@@ -12,6 +12,8 @@ type ClusterNode struct {
Label Label
// Labels []Label
// WorkPointer []*Workload
Flag *bool
Copy link
Member Author

Choose a reason for hiding this comment

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

Added a pair of bool/uint32 pointer to non pointer conversions to the e2e test.

@@ -10,6 +10,13 @@ func NodeToCore(s *Node, t *core.ClusterNode) {
}
t.ID = s.ID
t.Label = core.Label(s.Label)
t.Flag = &s.Flag
Copy link
Member Author

Choose a reason for hiding this comment

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

This shows you what the updated basic type conversion code looks like when crossing pointer/nonpointer boundaries.

leftRealType = leftPtrType.X
}

return &ast.IfStmt{
Copy link
Member Author

Choose a reason for hiding this comment

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

This lifted code from the existing area of code that handled the struct-to-struct conversions, which are different than basic type conversions for Go reasons.

Copy link
Member

@jmurret jmurret left a comment

Choose a reason for hiding this comment

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

🎉

@rboyer rboyer merged commit 33044b5 into main Oct 27, 2023
3 checks passed
@rboyer rboyer deleted the rboyer/fix-basic-pointer-conversion branch October 27, 2023 17:35
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