-
Notifications
You must be signed in to change notification settings - Fork 1
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
Error when applying to pointer field in fix mode #11
Comments
Hello, thank you for your interest in the project. Could you show the code (before the fix), which after the fix no longer works? You might also want to look at: #5 (comment) |
See bellow. type MyFoo struct
CancelPolicy *string
}
// f's type is *Foo
m := MyFoo{
- CancelPolicy: f.CancelPolicy,
+ CancelPolicy: f.GetCancelPolicy(), // cannot use f.GetCancelPolicy() (value of type string) as *string value in struct literal compiler(IncompatibleAssign)
} Therefore, I modified it myself as follows. +c := res.GetCancelPolicy()
m := MyFoo{
- CancelPolicy: f.CancelPolicy,
+ CancelPolicy: &c,
}
|
Now I understand. At this point, if you really need nil in a given field (rather than zero value), I would suggest adding m := MyFoo{
CancelPolicy: f.CancelPolicy, //nolint:protogetter
} |
I've run into this and would love to see it work out of the box. It seems to me that this linter should allow assigning the field directly when the destination type is known to be a pointer type. A potentially trickier thing to solve for is accessing a nested field safely but then assigning the raw field to a pointer field. |
Hi.
When I apply a pointer field in fix mode, I get a compile error(IncompatibleAssign).
Because the getter in the pointer field returns a value.
For example, protoc generates the following code.
version
The text was updated successfully, but these errors were encountered: