You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previous commits focused on checking for pointers and aliases more appropriately.
What emerged was two functions `realType` which gave us the concrete
native type (non-pointer, non-alias) an `unaliasType` which stripped
aliasing but only until it hit pointerness. They were sort of
inconsistently applied and in a few places I found the composition of
them to be weird.
I want to reframe those as:
1) `func nativeType(t) t` which removes all aliasing but retains pointerness. So for example:
```
type T1 string
type T2 *T1
type T3 *T2
type Foo struct {
Name *T3
}
```
Calling `nativeType()` on the `Name` member would yield `***string`.
This is what we want in most places. We need to retain pointerness
because (e.g.) we DO NOT support pointer to slice, and we want that to
fail, but we DO support pointer to string and we want that to succeed,
but `optional` needs to handle pointers and non-pointers differently.
We filter totally disallowed things early on, but if a pointer to slice
should sneak in somehow, this will refuse to generate bad code (fail in
an obvious way).
2) `func nonPointer(t) t` which removes all pointerness (if present),
but does not look past aliases. We needed to compose these both and call
`nonPointer(nativeType(t))` in a few places. E.g. when applying
`+k8s:format`, we need to know that the field is a string OR pointer to
string.
These two are more composable, I think. If you agree I can finish that
off this weekend and ping the PR. If not, would like to hear your
thoughts. Mostly the goal is put as many defensive checks in place as
possible. New validators will copy these ones and I want it to be as
clear as possible.
0 commit comments