-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
Better reflection detection #380
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add more tests? Including that e.g. fmt.Printf("%s\n", myType)
doesn't prevent a named type from being obfuscated, as that would have too many false positives.
Another test to include is a user-written API that uses reflection, e.g. defined in a sub-package inside the testdata input module.
Can we test that some simple protobuf code works correctly? Maybe some example code? |
I tested the go examples at https://github.com/protocolbuffers/protobuf/tree/master/examples, works! |
Sweet, we don't have to do it for this pr but you guys think it's possible to test against protobuf code in our tests? |
That's #240 :) protobuf is indeed one of the best candidates, due to its use of reflection and new-ish Go features like type aliases. |
@mvdan @capnspacehook I think this is ready. We should probably also tag a new release once this is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Thanks for bearing with me with the reviews. This is non-trivial, and I've been travelling for a week.
There are some edge cases that this PR might not cover yet; for example:
func indirectlyViaAddress(v interface{}) {
_ = reflect.TypeOf(&v)
}
func indirectlyViaMethod(v SelfInterface) {
_ = reflect.TypeOf(v.Self())
}
func indirectlyViaVariable(v interface{}, someCond bool) {
if someCond {
x := v
_ = reflect.TypeOf(x)
}
}
We can add more tests and improve with future PRs. Just something for you to keep in mind.
No description provided.